这个程序运行结果为什么总不对呢

gongyali2005 2007-02-06 10:25:34
package download;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class DownLoad {
static Frame f=new Frame("DownLoad");
static Label l=new Label("请输入URL地址: ");
static Panel p=new Panel();
static List ta=new List(6);
static TextField tf=new TextField("http://127.0.0.1",30);
//static TextArea ta=new TextArea(30,40);
static Button b=new Button("DownLoad");

public static void main(String[] args) {


p.add(l);
p.add(tf);
f.add(p,BorderLayout.NORTH);
f.add(ta,"Center");
f.add(b,"South");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}


});
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str=tf.getText();
try {
URL url=new URL(str);
URLConnection uc=url.openConnection();
ta.add("主机名: "+url.getHost());
ta.add("使用端口: "+url.getDefaultPort());
ta.add("文件类型: "+uc.getContentType());
ta.add("文件长度: "+uc.getContentLength());
InputStream is=uc.getInputStream();
FileOutputStream fos=new FileOutputStream("f:\\1.html");
//BufferedOutputStream bos=new BufferedOutputStream(fos);
DataOutputStream dos=new DataOutputStream(fos);
int data=0;
while((data=is.read())!=-1)
{
dos.write(data);
}
dos.close();
is.close();


}
catch (Exception ex) {
ex.printStackTrace();
}

}
});


f.setSize(400,300);
f.setLocation(150,150);
f.setVisible(true);
}
}
文件类型为NULL.
文件长度为-1
这是怎么回事.我输入的是http://127.0.0.1/jdk/A1.txt
...全文
193 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
syhan 2007-02-06
  • 打赏
  • 举报
回复
检查一下防火墙吧
gongyali2005 2007-02-06
  • 打赏
  • 举报
回复
输入http://127.0.0.1/A.java
结果为:
主机名:127.0.0.1
端口:80
文件类型为NULL.
文件长度为-1
gtw0520 2007-02-06
  • 打赏
  • 举报
回复
http://127.0.0.1/jdk/是一个ftp服务吗?或者是一个http服务,你要保证服务是打开的,并监听正确的端口
fengmingjie 2007-02-06
  • 打赏
  • 举报
回复
1.你访问的机器,有让你读写文件的权限吗,必须修改你访问机器的读写文件权限即修改java的本地安全策略
2.你访问的文件的路径是否正确
HxIn_it 2007-02-06
  • 打赏
  • 举报
回复
你A1.txt这个文件都不知道放在哪?
gongyali2005 2007-02-06
  • 打赏
  • 举报
回复
难道CSDN里只有问问题的.没有回答问题的?更没有跟贴的?

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧