In the app I’m developing for Android I’m letting users create files specific to my application with the extension “.rbc”. So far I have been successful in creating, writing to, and reading from these files.
Right now I am trying to count the number of these files that exists. I’m not particularly familiar with Java and I’m just beginning programming for Android so I feel a bit lost. All of my attempts so far at doing this have not been able to locate any files with my extension.
So I basically have two questions I need answered so that I can figure this out:
Where is the default directory where Android stores files created by an application?
Do you have any examples do you can give me of counting files with a specific extension on Android?
Thank you very much in advance for your time.
Some tests showed me that the default directory where Android stores files created by an application using
Context.getFilesDir()is/data/data/<your_package_name>/filesTo count the files in any given directory you use
File.listFiles(FileFilter)over the root dir. Your FileFilter should then be something like this (to filter for “.rbc” files):If you have some kind of directory structure you need to recursively search then you will have to
File.listFiles(FileFilter)over the entire directory structure. And it should be something like:And where
DirFilterwould implementsFileFilterthis way: