![](/img/trans.png)
[英]Copying directories and files from res/raw folder to sd card - 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
,您必须在自己的实现中进行处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.