日期:2014-05-18 浏览次数:20661 次
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
URL url = new URL("http://g3.ykimg.com/1100641F4651E8AB8200290955DEA7F39F0E12-D63B-A85A-C8BD-7919DD69CAB9");
URLConnection conn = url.openConnection();
byte[] byteBuffer = new byte[4096];
InputStream is = conn.getInputStream();
FileOutputStream fos = new FileOutputStream("C:/Users/zhangxinxin/Desktop/test.jpg");
int len = 0;
int off =0;
while((len=is.read(byteBuffer))!=-1)
{
fos.write(byteBuffer, off, len);
}
is.close();
fos.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}