try {
URL url = new URL(file_url);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/download";
File file = new File(PATH);
if(!file.exists()) {
file.mkdirs();
}
String name=String.valueOf(code)+".mp4";
File outputFile = new File(file,name);
FileOutputStream fos =
new FileOutputStream(outputFile);//this line
InputStream is = c.getInputStream();
int fileLength = sizeoffile;
byte[] buffer = new byte[4096];
int len1 = 0;
long total = 0;
while ((len1 = is.read(buffer)) != -1) {
total += len1;
if (fileLength > 0)
publishProgress((int) (total));
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
i want to download file with async class but it error when i rather to find the file path? this is a error in up to android 6? java.io.FileNotFoundException: /sdcard/downloadedfile.jpg: open failed: ENOENT (No such file or directory)
i added these permissions but doesn't work!