Created
August 14, 2013 16:18
-
-
Save wdfx100/6232682 to your computer and use it in GitHub Desktop.
URL类的图片下载
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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