Cannot find the created .txt file in android local storage

Summary When creating the txt file in android's local or internal storage, file explorer is not able to find the created file. Description I have an app which sotores the array list to txt file and reads it back when it needed. Function to write the file

. private void writeToFile(ArrayList arrayList, String Filename) < try < FileOutputStream outputStreamWriter = requireContext().openFileOutput(Filename, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(outputStreamWriter); Log.d(TAG, "writeToFile: arraylist "+arrayList.size()); oos.writeObject(arrayList); oos.close(); outputStreamWriter.close(); >catch (IOException e) < Log.e("Exception", "File write failed: " + e.toString()); >> . 
function to read from file
. private Object readFromFile(String Filename) < try < FileInputStream fis = requireContext().openFileInput(Filename); ObjectInputStream ois = new ObjectInputStream(fis); Object object = ois.readObject(); return object; >catch (Exception ex) < Log.d(TAG, "readFromFile: exception "+ex.toString()); return null; >> . 
  1. I tried to get write and read permission. But, as android 10+ doesn't need any permission for writing or reading in ScopedStorage It didn't effect anything.
  2. I tried with creating the dir using requireContext().getExternalFilesDir(null) which created the files directory inside Android folder and then I tried to write and read the file. But, Dir is empty.
  3. I even tried checking show hidden files options in file explorer. But, no luck.
asked Jul 9, 2021 at 7:39 Anirudhdhsinh Jadeja Anirudhdhsinh Jadeja 753 1 1 gold badge 5 5 silver badges 24 24 bronze badges

1 Answer 1

According to docs, by default openFileOutput will create a file inside Android/data/packagename/files

No, it will not. openFileOutput() writes to the same location as you get via getFilesDir() , which is what the Android SDK refers to as internal storage.

But, file explorer is not showing the dir either.

Only your app has access to your portion of internal storage. Using development tools, Android Studio's Device File Explorer can show you internal storage for debuggable apps, such as debug builds of your app.

I tried with creating the dir using requireContext().getExternalFilesDir(null) which created the files directory inside Android folder and then I tried to write and read the file. But, Dir is empty.

On Android 10+, other apps do not have access to your app-specific locations on what the Android SDK refers to as external storage.