0

I try to code an app to write a file txt. I found a lot of things on internet but not what i'm really looking for.

    String path=Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.txt";
    File file = new File(path);
    FileOutputStream is = new FileOutputStream(file);
    OutputStreamWriter osw = new OutputStreamWriter(is);
    Writer w = new BufferedWriter(osw);
    w.write("Je cree le fichier essai.txt");
    w.close();
} catch (IOException e) {
    Log.i("Info", "Problem writing to the file statsTest.txt");
}

Here is my code, i don't understand why the file is not created. I want to create the file on the storage of my phone and not as a hidden file of the application (So not the mode context Private).

VikaS GuttE
  • 1,636
  • 2
  • 14
  • 38
lina
  • 1

1 Answers1

0

https://developer.android.com/training/data-storage/files#PublicFiles

try:

File file = new File(Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES), albumName);
S. Souza
  • 110
  • 7