如何访问 res/raw 文件夹或 android 中任何其他位置的文件?

How can I access files in res/raw folder or any other location in android?

我一天前发布了类似的问题,但我在这里简化了我的问题,希望得到解决。 我想我知道在使用 '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,您必须在自己的实现中进行处理。