4

I want to list folders and files in asset folder, but I find out i empty. I searched for the answer but it did not helped, on google, stackoverflow and many others.

I tried many approaches with AssetManager and only that gave some output was:

getAssets().list("/");

But assets folder it listed was empty...

I run application from eclipse (device on usb). Can anyone tell me what I do wrong? I have feeling that assets folder I open is not form my application...

Thanks in advance!

ehrid
  • 95
  • 8

4 Answers4

5

I was using getAssets().list("/"); and it returned a list of the files in the root of the app:

D/        (25498): Listing files in /
D/        (25498): AndroidManifest.xml
D/        (25498): META-INF
D/        (25498): assets
D/        (25498): classes.dex
D/        (25498): lib
D/        (25498): res
D/        (25498): resources.arsc

Then I tried listing "/assets" but it was always empty. Then I found out that a relative path is needed and / for the root folder can not be used.

getAssets().list(""); lists the files in the root of the assets folder.

focs
  • 182
  • 2
  • 10
0

Try this:

AssetManager assetManager = appContext.getAssets();
String[] filelist = assetManager.list("");
Wagner Michael
  • 2,172
  • 1
  • 15
  • 29
0

You can get the assets files like this:

try {
    Resources res = getResources();
    AssetManager am = res.getAssets();
    String fileList[] = am.list("/");
} catch (IOException e) {
    e.printStackTrace();
}
113408
  • 3,364
  • 6
  • 27
  • 54
  • Yeah, I tried this too. All approaches with AssetManager that I found on google I tried. – ehrid Aug 25 '14 at 17:15
0

I see you were using Eclipse, I switched to Android Studio but had the same problem. Comparing many answers led me to this:

https://stackoverflow.com/a/33542563/524355

The asset folder is "next" to the res folder (in AS, there is even a wizard for it). I put it manually "into" the res folder that's why asset folder was gone/not compiled into the apk! If this is done by the build tools that you use in Eclipse (ADT) you might have suffered from the same situation.

assets not inside but parallel to res folder

Community
  • 1
  • 1
CaptainCrunch
  • 1,230
  • 14
  • 15