【问题标题】:How can I access files in res/raw folder or any other location in android?如何访问 res/raw 文件夹或 android 中任何其他位置的文件?
【发布时间】:2015-02-20 15:18:32
【问题描述】:

我在一天前发布了类似的问题,但我在这里简化了我的问题,希望能得到解决。 我想我知道在使用“filename.ext”读取文件时,我使用

InputStream inputStream = getResources().openRawResource(R.raw.filename);

但是我如何访问多个文件?我需要一个函数看起来像

InputStream inputStream[] = getResources().openRawResource(R.raw.*.*);

谢谢!

【问题讨论】:

标签: java android file-io


【解决方案1】:

如果您将文件放在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,您必须在自己的实现中处理。

【讨论】:

  • 非常感谢您的帮助。这就是我想要的。 :)
猜你喜欢
  • 1970-01-01
  • 2014-06-17
  • 1970-01-01
  • 2011-11-24
  • 2016-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多