10

I have some files in the assets folder of my project, and I want to list them, so I put this in my code:

File dir = new File("com.packagename/assets/fonts");
File[] fileList = dir.listFiles();

Which path should I put to make it work? I want it so users could install new fonts (I don`t know how to do this yet) so I need to list all the fonts in the folder, including post-installed fonts. If there is any other solutions, please share.

3
  • What language is this written in? It looks like Java... Commented Nov 14, 2012 at 3:40
  • i'm sorry i hadn't specified that it's an Android project Commented Nov 14, 2012 at 15:56
  • You will always get better results with a descriptive question (i.e. using proper tags, using code in your question, and including the error message if there is one). Also if someone solves your problem you should accept their answer by clicking the checkmark under the upvote/downvote arrows. Commented Nov 14, 2012 at 17:41

1 Answer 1

7

Assets and resources are accessible using file:///android_asset and file:///android_res.

But in this case you will want to do something like this :

Resources res = getResources()
AssetManager am = res.getAssets();
String fileList[] = am.list(dirFrom);

if (fileList != null) {   
   for ( int i = 0;i<fileList.length;i++) {
        Log.d("",fileList[i]); 
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

are you sure the resources part is required?? i did something similar without it and it worked
It's a directory string such as "images" where you're searching for your assets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.