Issue
I create some folders into assets. Each folder contains files that I would like to list. I am using following code but I always get a null value for fileList. Thank you.
I used, listFiles("/assets/images/","nothing");
private void listFiles(String dirFrom, String dirTo) {
File f = new File(dirFrom);
String fileList[] = f.list();
if (fileList != null)
{
for ( int i = 0;i<fileList.length;i++)
{
Log.d("",fileList[i]);
}
}
}
Solution
You'll probably want to do this:
private void listFiles(String dirFrom) {
Resources res = getResources(); //if you are in an activity
AssetManager am = res.getAssets();
String fileList[] = am.list(dirFrom);
if (fileList != null)
{
for ( int i = 0;i<fileList.length;i++)
{
Log.d("",fileList[i]);
}
}
}
Also your function call should be: listFiles("images");
if you want to list images.
Answered By - user
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.