您的位置:首页 > 理论基础 > 计算机网络

Java学习笔记之网络编程基础-通过URL获取网络图片

2010-11-07 00:53 1006 查看
package com.kkoolerter;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.URL;

public class GetImageByURL {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
URL url = new URL(
"http://hiphotos.baidu.com/baidu/pic/item/697e2a3fb95157a655e7234c.jpg");
DataInputStream dis = new DataInputStream(url.openStream());
OutputStream os = new FileOutputStream(new File("download.jpg"));
byte buffer[] = new byte[1024];
int len = -1;
while((len = dis.read(buffer))!=-1){
os.write(buffer, 0, len);
}

os.close();
dis.close();

}

}
本文出自 “有思想的代码” 博客,请务必保留此出处http://wujuxiang.blog.51cto.com/2250829/416690
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: