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; >> .
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.