I am downloading a file from server with help of a URL provided through web service.
I am successful for every version of devices but getting exception in OS 4.1 devices.
I am using below code:
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;
}
}
I am getting java.io.FileNotFoundException at line c.getInputStream();
please suggestion me to solve this problem.
I am planning to use the internal memory but as user cant access the internal memory.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…