java 请教如何 下载验证码图片到本地
比如说我想把http://www.400gb.com/randcodeV2.php?fid=18788565&rand=0.7062261414248496 中的验证码以图片形式下载到本地的一个位置上 如何实现 谢谢~
java
--------------------编程问答--------------------
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();
补充:Java , Java相关