Issue
Got a brand new project using Google's new Android Studio IDE.
I'm trying to load a simple text file using an InputStreamReader
. I'm getting a file not found exception. Now there isn't any assets/ folder. I tried to create one and add my file at many different spots (at the root of the project, at the root of the .java file, etc...) I've tried to move the file around but still get the file not found.
Now that never was a problem using Eclipse as there is an assets folder created by any template.
Does anyone know where should the assets go to or how to load them?
Here is the code used, it fails at .open():
InputStream iS = resources.getAssets().open("bla.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(iS));
I also tried this code in Eclipse, it works and the file contents get loaded. So there's probably a step needed in Android Studio.
Solution
- Step 1: Open in Name_Project-Name_Project.iml file.
- See the line : option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets"
- Step 2: Create a sub-folder "assets" in main folder.
- Step 3: Put file in this folder.
- Step 4: Load it. Done.
Answered By - FIT226557
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.