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<ImageModel> 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;
}
}
....
So, far everything is working fine. It is writing and reading the file. But, I cannot find the same txt file in the device explorer or file manager. According to docs, by default openFileOutput
will create a file inside Android/data/packagename/files
. But, file explorer is not showing the dir either.
But, App is writing and reading the file. When I printed size of object returned by readFromFile()
It printed the expected size. But, I can't find the file inside file explorer.
Things I tried
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.I tried with creating the dir using
requireContext().getExternalFilesDir(null)
which created thefiles
directory insideAndroid
folder and then I tried to write and read the file. But, Dir is empty.I even tried checking
show hidden files
options in file explorer. But, no luck.