WebbTraverse
WebbTraverse

Reputation: 1

Android : open failed: ENOENT (No such file or directory) on new FileWriter on a first application launch

In the following method, I have an exception ( open failed: ENOENT (No such file or directory) ) in new FileWriter(f.getPath()) ONLY on the first application launch after installation (then - close and reopen the app - it works) :

public static boolean writeContent(File f, String s) {

    try (BufferedWriter writer = new BufferedWriter(new FileWriter(f.getPath()))) {
        writer.write(s);
        writer.close();
        return true;
    } catch (IOException e) {
         e.printStackTrace();
        return false;
    }
    } 

I have the following permission in the manifest :

  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

File is defined with a method getExternalFilesDir() and with <external-files-path> in the file_paths.xml file.

Any idea ? Thanks.

Upvotes: 0

Views: 683

Answers (0)

Related Questions