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
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.
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.
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.
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?
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With