Skip to content

Instantly share code, notes, and snippets.

@wdfx100
Created August 14, 2013 16:18
Show Gist options
  • Save wdfx100/6232682 to your computer and use it in GitHub Desktop.
Save wdfx100/6232682 to your computer and use it in GitHub Desktop.
URL类的图片下载
URL url = new URL("http://www.kaishengit.com/images/2013.jpg");
URLConnection conn =url.openConnection();
InputStream stream = conn.getInputStream();
File file = new File("F:/tupian.jpg");
OutputStream out = new FileOutputStream(file);
BufferedInputStream bis = new BufferedInputStream(stream);
BufferedOutputStream bos = new BufferedOutputStream(out);
int len = -1;
byte[] b = new byte[1024];
while((len=bis.read(b))!=-1){
bos.write(b, 0, len);
}
bos.flush();
bos.close();
bis.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment