Answer the question
In order to leave comments, you need to log in
I get an error open failed: EROFS (Read-only file system), how to fix it?
I'm trying to save the downloaded file and I get - java.io.FileNotFoundException: /1.gif: open failed: EROFS (Read-only file system)
How did you fix it??
marked in the code where the error occurs.
private String saveFilePatch = "/1.gif";
private ProgressDialog dialog = null;
private String urlFile="https://vk.com/doc430279622_445877224?hash=d20c78fff02c29f267&dl=GQZTAMRXHE3DEMQ:1496394942:6d9c703cd7409eda1b&api=1&no_preview=1";
private void downloadFile(String url, String saveFilePatch){
try {
File SaveFile = new File(saveFilePatch);
URL u = new URL(url);
URLConnection con = u.openConnection();
int lengthofContext = con.getContentLength();
DataInputStream dataInputStream = new DataInputStream(u.openStream());
byte[] buffer = new byte[lengthofContext];
dataInputStream.readFully(buffer);
dataInputStream.close();
FileOutputStream fos = new FileOutputStream(SaveFile);
<b> // ошибка выпадает в этой строке</b>
DataOutputStream dataOutputStream = new DataOutputStream(fos);
dataOutputStream.write(buffer);
dataOutputStream.flush();
dataOutputStream.close();
fos.close();
hideProgressIndicator();
}catch (IOException e){
hideProgressIndicator();
e.printStackTrace();
}
catch (Exception e){
e.printStackTrace();
}
}
private void hideProgressIndicator() {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.dismiss();
}
});
}
public void onClickBtnTwo(View view) {
if (urlFile != "") {
dialog = ProgressDialog.show(MainActivity.this, "", "Download...", true);
new Thread(new Runnable() {
@Override
public void run() {
downloadFile(urlFile, saveFilePatch);
}
}).start();
}else {
System.out.println("null photo");
}
}
в манифесте прописано
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question