I posted a day ago similar question, but I simplified my problem here so hoping to get resolved. I think I know when reading a file with 'filename.ext', I use
InputStream inputStream = getResources().openRawResource(R.raw.filename);
But how I can access multiple files? I need a function looks like
InputStream inputStream[] = getResources().openRawResource(R.raw.*.*);
Thanks!
If you place your files in assets/
instead of res/raw/
, then something like this might work for you:
AssetManager am = getAssets();
String assetFileNames[] = am.list("");
InputStream inputStream;
for(String assetFileName : assetFileNames) {
inputStream = am.open(assetFileName);
// Replace with whatever you want to do with the file here
processAssetFile(inputStream);
inputStream.close();
}
Note that several of the methods above throw java.io.IOException
, which you'd have to handle in your own implementation.
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.