0

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!

ben Heo
  • 141
  • 2
  • 12
  • 1
    See [Android, how do can I get a list of all files in a folder?](http://stackoverflow.com/questions/6539715/android-how-do-can-i-get-a-list-of-all-files-in-a-folder) – ρяσѕρєя K Feb 20 '15 at 06:24
  • THank you for the helpful link. I searched similar topics before I post and failed but this is great. Thank you so much! – ben Heo Feb 20 '15 at 07:58

1 Answers1

3

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.

unrulygnu
  • 1,596
  • 13
  • 16