My app saves voice recording on external storage. The user inputs a filename after the recording, and I add that file name to arraylist and save that arraylist using the SharedPreferences.Now, if a user goes to the directory and renames the file, the name of the file will not change in the SharedPreferences. This is a problem because when the list of files is shown in my app, I open it by using the name saved in SharedPreferences. So if a file is renamed, that name will not be in the SharedPreferences, and will crash my app. Is there anyway I can avoid this, for example - can I save a file and retrieve it and open it irrespective of what it's name is? How would I do that?
I'm surprised by the lack of similar questions, which makes me feel I'm missing an obvious easier way of saving and retrieving files.
This gives you a list of all files within a specified directory:
File directory = new File("/path/to/directory/");
File[] files = directory.listFiles();
for( File file : files ) {
doStuffWithFile( file );
}
No need to know the file names, just the directory.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.