圖片下載

weixin_33860722發表於2018-03-17

String urlPath="";
String destPath = "";
URL url = new URL(urlPath);
DataInputStream dataInputStream = new DataInputStream(url.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(new File(destPath));
byte[] bytes = new byte[1024];
int length;
while ((length = dataInputStream.read(bytes)) > 0) {
    fileOutputStream.write(bytes, 0, length);
}
dataInputStream.close();
fileOutputStream.close();

相關文章