81,122
社区成员




URL url = new URL("网络图片地址");
// 打开连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
connection.setConnectTimeout(5 * 1000);
InputStream inputStream = connection.getInputStream();
byte[] bs = new byte[1024];
int len;
File sf=new File(exp_path); // /home/
if(!sf.exists()){
sf.mkdirs();
}
OutputStream os = new FileOutputStream(sf.getPath()+"\\123.png");
// 读取
while ((len = inputStream.read(bs)) != -1) {
os.write(bs, 0, len);
}
os.flush();
// 关闭
os.close();
inputStream.close();