28
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

4
  • 1
    That looks correct -- are any exceptions such as IOException thrown? Commented Jun 13, 2010 at 21:20
  • Yes, but strangely the exception is empty, no "cause" Commented Jun 13, 2010 at 22:13
  • If you can paste the stack trace into your original question, that'd be quite helpful. Commented Jun 13, 2010 at 23:56
  • Is it possible that you are loading the input stream using the wrong locale? Commented May 4, 2011 at 3:01

4 Answers 4

44

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?

Sign up to request clarification or add additional context in comments.

Comments

8
"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.

Comments

6

Is your asset file over 1 MB?

I notice that I get the same odd, empty IOException if I try to open an asset that is over this size. The fact that it is in a subfolder could be a red herring. I'm trying to open a large text file so I can workaround this limit by splitting it up. Can you do something similar with your .db3 file?

1 Comment

omfg wtf!!! this is a stupid error and they should fix this. thank you so much for writing this answer, it's certainly the same case for me where i had an .ogg file under "music/blah.ogg" which didn't work because it was well over 1 mb, but another file "music/foo.ogg" works and it's only 26 kb...
0

I had a similar issue: Changed the subfolder name from "mp3" to "mpthree" and the files were found.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.