I am trying to create a file in the internal memory (not on a flash drive).

File file = new File(getApplicationContext().getFilesDir(), "123.txt"); FileOutputStream outputStream; try { outputStream = openFileOutput("123.txt", Context.MODE_PRIVATE); outputStream.write("123.txt".getBytes()); outputStream.flush(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } 

The file is not created, I look in the data / data / folder and then it is empty, there is not even a folder with the name of the application. What am I doing wrong?

  • Are the rights vyvevelny? What you see in data / data is so easy not to climb. And the folder with the application package is always there. - pavel
  • I use genimotion, it allows me to climb into the root (root) - Nicola Krivosheya
  • Permission specified in the manifest? WRITE_EXTERNAL_STORAGE? - Android Android

1 answer 1

Try this

 public static File createFile(String directory, String name){ File result; do { result = new File(directory, name); } while (!result.createNewFile()); return result; } 

Change your code to

 File file = createFile(getApplicationContext().getFilesDir(), "123.txt");