I am trying to access a file for xml parsing with this:
InputStream inputStream = context.getAssets().open("/mnt/sdcard/cat/bird/flowers.xml");
When it runs i get the following error:
06-13 23:13:22.620: W/System.err(3118): java.io.FileNotFoundException: /mnt/sdcard/cat/bird/flowers.xml
06-13 23:13:22.620: W/System.err(3118): at android.content.res.AssetManager.openAsset(Native Method)
06-13 23:13:22.620: W/System.err(3118): at android.content.res.AssetManager.open(AssetManager.java:314)
06-13 23:13:22.620: W/System.err(3118): at android.content.res.AssetManager.open(AssetManager.java:288)
I have checked the spelling of the file and i have checked the location several times. The file is there and correctly named. What is going on here?
getAssets().open(...) is used to access files which you have packaged with the .apk file by placing them in the project's
Trying to open a file with this path...
AssetManager will try to look for a packaged file which you originally placed in your project with the following path...
Make sure you have the following permission. (may not be needed for just reading). Also on some devices reading from sdcard has been restricted.
Also do NOT use hardcoded paths, use the following to get external storage path.
String path = Environment.getExternalStorageDirectory() + "/cat/bird/flowers.xml";
getAssets() is generally used to get access to files in the assets folder in your project. You should use something like:
InputStream inputStream = new FileInputStream("//sdcard//cat//bird//flowers.xml");