Android list files in private app store

I am developing an Android application and I need the save and load functions.

I want to save important data in a private application store using this function:

public static void save(Object file, String fileName, Context context) throws IOException, FileNotFoundException { FileOutputStream fos = context.openFileOutput(fileName, context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(file); oos.flush(); oos.close(); fos.close(); System.out.println(TAG + ": File saved successful!"); } 

I also wrote a method for loading data. This works because I know the exact file name.

Now I need to do dynamic file saving with dynamic name generation. How can I list the files stored in the repository of attachment applications? So can I upload the exact file?

+4
source share
1 answer

Here you go!

 File dir = getFilesDir(); File[] subFiles = dir.listFiles(); if (subFiles != null) { for (File file : subFiles) { // Here is each file } } 
+7
source

Source: https://habr.com/ru/post/1441067/


All Articles