Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Assets with sub folders

Tags:

android

assets

InputStream myInput = myContext.getAssets().open("MyFolder/" + "MyFile.db3"); 

I have a file in the assets folder in a sub folder as above. It doesn't get the file though, is there a special way to specify a sub folder in the assets folder?

Ian

like image 517
Ian Vink Avatar asked Jun 13 '10 21:06

Ian Vink


People also ask

How do I add a folder to assets?

Step 1: To create an asset folder in Android studio open your project in Android mode first as shown in the below image. Step 2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder. Step 3: Android Studio will open a dialog box. Keep all the settings default.

Can a folder have sub folders?

A subfolder is a folder stored inside another folder. Subfolders help you organize your files more completely. Each subfolder should be used to store files related to each other. For example, you might have one folder for files related to a job search.

What is the use of assets folder in Android?

Assets provide a way to include arbitrary files like text, xml, fonts, music, and video in your application. If you try to include these files as "resources", Android will process them into its resource system and you will not be able to get the raw data.


2 Answers

Edit: was wrong about subfolders.
This code works just fine on 1.5 (for a file sample.txt placed under sub folder in assets):

InputStream is = getAssets().open("sub/sample.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; while ((line = br.readLine()) != null) {     Log.e("wtf", line); } br.close(); 

Are you sure you've got the names right?

like image 172
yanchenko Avatar answered Oct 14 '22 01:10

yanchenko


"MyFolder/" + "MyFile.db3" 

A filename for files added to the assets folder must be in lowercase letter. so,a filename such as MyFolder and Myfile.db3 is invalid. Rename them to "myfolder" and "myfile.db3",then everything will be fine.

like image 30
Spark Avatar answered Oct 14 '22 02:10

Spark