Unable to get files in Android assets directory
NickName:Bob Sands Ask DateTime:2011-08-29T23:40:43

Unable to get files in Android assets directory

I am trying to find files located in assets. I have .txt, .gif, and .db files that are there in an eclipse android project but do not display when I run the following code:

AssetManager am = getAssets();
try {
    String list[] = am.list("/");
    I=0;
    Str="";
    while (list[] != null) {
        Str=Str+"\r\n"+list[I];
        I++;
    }
}
catch(exception e){
}

I get this list:

AndroidManifest.xml
META-INF
assets
classes.dex
com
res
resources.arsc

This list does not include any of the files in assets.

Project properties is currently set to not include assets folder in the build path. When I do include the assets folder in the build path, it gives me the same list with ".." as the first file.

I have tried changing "/" in the third line to "/assets/" but get nothing returned.

Changing the Android Project Build Target between Android 2.3.1 and Android 2.1-update1 appears to have no effect.

Is there a setting in the project properties that is required for files in assets to be included in the build? Is there a different name for the assets directory using AssetManager?

Copyright Notice:Content Author:「Bob Sands」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7232385/unable-to-get-files-in-android-assets-directory

More about “Unable to get files in Android assets directory” related questions

Unable to get files in Android assets directory

I am trying to find files located in assets. I have .txt, .gif, and .db files that are there in an eclipse android project but do not display when I run the following code: AssetManager am = getA...

Show Detail

Android assets no such file or directory

In my android project I have created an assets folder in which I have added some json files and I want to read them with a stringBuffer. The assets folder is listed inside src/main. So far I have a...

Show Detail

Get folders name from Assets directory

I'm trying to get the names of my folders in "assets". I can get the names of the files with an AssetManager by using the method assetManager.list(). But the problem is that it return only files' n...

Show Detail

How to delete directory containing files in the assets directory in Android

How could you delete a directory containing files on android assets directory. I tried doing this but does not work. try { listaAssets = getAssets().list(""); } catch (IOException e)...

Show Detail

How to add subdirectories and specific files to Android assets

In my repo root I have my data directory, Android project directory, and some other things. I'm trying to add my data directory as a subdirectory of the assets dir. I've tried the below code, but i...

Show Detail

Android assets as a File

I want to add a hierarchy of files to my android program and use all of them as files. Is it possible that I add them to my assets folder and then get Files and directories of the assets folder as ...

Show Detail

Android unable to create files directory

On Samsung Galaxy S5 (Android 4.4.2), after installing, I click the app, and it crashes. Crash stack is 08-18 13:58:48.191 10816-10851/com.example.galina.demo W/ContextImpl: Unable to create files

Show Detail

How to extract .obb file in android to the assets directory?

I am using libraries provided by the android sdk for apk expansion file to download the obb file, however I am not sure how to extract these files to the correct directory or if it is even possible...

Show Detail

access files from assets/www directory

let's say I've got a file called foo.html sitting (quite comfortable) in my assets/www directory (next to my index.html). I'd like to copy that file to another location on the device. My first app...

Show Detail

Android copy from assets to files directory

Hi I have a a collection of json files in my assets/data/ folder on launch i want to check to see if the files exists in the internal files directory if the any of them dont exist i want to copy them

Show Detail