我准备了从服务器下载图像并存储在 sdcard 中的代码。为此我准备了代码,
URL url;
try {
url = new URL("http://myserver_path/applikaza/appstore/apks/ScrResoluton/scrresolution.jpg");
input = url.openStream();
String storagePath = Environment.getExternalStorageDirectory().toString();
String basepath = storagePath + "/Guayama/" + folderName;
output = new FileOutputStream(basepath + "/home.png");
byte[] buffer = new byte[5000];
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
output.write(buffer, 0, bytesRead);
}
} catch (MalformedURLException e) { // TODO Auto-generated catch block
e.printStackTrace();
} finally {
output.close();
input.close();
}
但是在 . 我认为在某些地方犯了 NullPointerException output.close()
错误。请帮助我。