I need to retrieve a list of all files of a certain type on my internal and external storage. I found this (-> List all of one file type on Android device? ) example, but it's very mp3 specific.
My app creates a .zip file which is renamed to the extension *.message
Another activity should display a list of all available .message files, from which the user can choose one to open it.
Does anyone has an idea how to begin?
Thanks!
To obtain a list of files with a specific extension you can use File.list()
with a FilenameFilter
. For example:
File dir = new File(".");
String[] names = dir.list(
new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return name.endsWith(".message");
}
});
Note that the returned strings are file names only, they do not contain the full path.
Here it is
File root = new File(globalVar.recordDir);
{
try {
if (root.listFiles().length > 0) {
for (File file : root.listFiles()) {
if (file.getName().endsWith(".mp3")) {
//DO somthings with it
}
}
}
} else {
}
} catch (Exception e) {
}
}
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.