我正在借助通过 Web 服务提供的 URL 从服务器下载文件。我对每个版本的设备都很成功,但在 OS 4.1 设备中出现异常。我正在使用以下代码:
public static Boolean DownloadFile(String fileURL, File directory) {
try {
FileOutputStream f = new FileOutputStream(directory);
URL u = new URL(fileURL);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
f.write(buffer, 0, len1);
}
f.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
我在c.getInputStream();行收到 java.io.FileNotFoundException 请建议我解决这个问题。
我打算使用内部存储器,但由于用户无法访问内部存储器。