日期:2014-05-20 浏览次数:20564 次
URL url = new URL(<a href="http://shop.10010.com/login/getNumberCheckCode.action">http://shop.10010.com/login/getNumberCheckCode.action</a>); //返回的是4位验证码的图片
File outFile = new File("D:\\image\\a.jpg");
OutputStream os = new FileOutputStream(outFile);
BufferedReader bf = new BufferedReader(new InputStreamReader(url.openStream()));
InputStream is = url.openStream();
byte[] buff = new byte[1024];
while(true) { //要注意这种写法
int readed = is.read(buff);
if(readed == -1) {
break;
}
byte[] temp = new byte[readed];
System.arraycopy(buff, 0, temp, 0, readed); // 这句是关键
os.write(temp);
}
is.close();
os.close();