微信のアイコンのリンクから画像をダウンロードしてサーバーに着きます
897 ワード
public static String getImageByUrl(String imageurl, String savepath, String name) {
try {
// URL
URL url = new URL(imageurl);
//
URLConnection con = url.openConnection();
//
InputStream is = con.getInputStream();
// 1K
byte[] bs = new byte[1024];
//
int len;
File file = new File(savepath);// (String) property.get("ewmPath"));
if (!file.exists()) {
file.mkdirs();
}
//
OutputStream os = new FileOutputStream(savepath + name);
//
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
}
// ,
os.close();
is.close();
return name;
} catch (Exception e) {
return "error";
}
}