// 图片下载函数
public static String makeImg(String imgUrl, String fileURL) {
String imgFile="";
try {
// 创建流
BufferedInputStream in = new BufferedInputStream(new URL(imgUrl)
.openStream());
// 生成图片名
int index = imgUrl.lastIndexOf("/");
String sName = imgUrl.substring(index + 1, imgUrl.length());
System.out.println(sName);
imgFile=fileURL+sName;
// 存放地址
File img = new File(fileURL + sName);
// 生成图片
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(img));
byte[] buf = new byte[2048];
int length = in.read(buf);
while (length != -1) {
out.write(buf, 0, length);
length = in.read(buf);
}
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return imgFile;
}
图片下载
最新推荐文章于 2024-07-17 18:22:26 发布