读取网络文件问题

skycncomp 2005-06-20 05:46:48
我读网络中的一张图片,想在保存到本地如下::

String path = "http://www.sun.com/im/a.gif";
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(path)));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("d://aa")));

int i = 0;
byte[] b = new byte[1024];
while ((i = bis.read(b)) != -1) {

bos.write(b);
}

bis.close();
bos.close();

为什么总是报异常如下::

java.io.FileNotFoundException: http:\www.sun.com\im\a.gif (文件名、目录名或卷标语法不正确。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at cncomp.internet.operatorfile.Internet.savePic(Internet.java:93)
at cncomp.internet.operatorfile.ReadWeb.main(ReadWeb.java:26)
Exception in thread "main"
...全文
82 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
humanity 2005-06-20
  • 打赏
  • 举报
回复
不是 BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("http://www.sun.com/im/a.gif")));

因为你这个地址不是文件,

你要用 URL url =new URL("http://www.sun.com/im/a.gif");
InputStream is = url.openStream();

62,616

社区成员

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

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