简体   繁体   中英

Android: any way to enumerate raw resources

Say I have a number of files stored under res/raw. Eg:

yeh_vidhi_mangal.txt
om_jai_mahavir.txt
tumse_laagi_lagan.txt

I would like to iterate over these files in code. Something like:

Resources myResources = getResources();
for(int i = 0; i < ...;i++)
{
   int id_of_ith_resource = ....
    InputStream in = myResources.openRawResource(id_of_ith_resource);
   // do my stuff
}

the dots ... need to be filled in

if you place your files into assets directory instead of the raw directory you can then use AssetManager.list() method to enumerate them. Not sure why you need them in raw directory as opposed to assets directory.

if your raw folder contain static files only means, files does not generate dynamically then use this method,

int num[] = {R.raw.yeh_vidhi_manga,R.raw.om_jai_mahavir,R.raw.tumse_laagi_lagan};

for(int resId in num){

InputStream ins = getResources().openRawResource(resId);
//do the stuff
}

else if content are generated dynamically from remote folder then use AssetManager and for iterate file AssetManager.list();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM