我一天前发布了类似的问题,但我在这里简化了我的问题,希望能够得到解决。 我想我知道当读取带有“filename.ext”的文件时,我使用
InputStream inputStream = getResources().openRawResource(R.raw.filename);
但是我如何访问多个文件呢?我需要一个类似的函数
InputStream inputStream[] = getResources().openRawResource(R.raw.*.*);
谢谢!
最佳答案
如果您将文件放在 assets/
中而不是 res/raw/
中,那么类似这样的操作可能适合您:
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();
}
请注意,上面的几个方法会抛出 java.io.IOException
,您必须在自己的实现中处理它。
关于java - 如何访问 res/raw 文件夹或 android 中任何其他位置的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28622759/