Adil Waqar Adil Waqar - 1 year ago 87
Android Question

Exception while reading file from SD Card

I am trying to read an XML file from the SD card. The path is fine, but it says: /file:/mnt/sdcard/Reginfo/output/data.xml (No such file or directory)

Here is how I am attempting to read this file:

FileInputStream file = new FileInputStream(new File("file://"
+ Environment.getExternalStorageDirectory()
+ "/RegInfo/output/data.xml"));

I can see this file in the
folder in File Explorer.

Answer Source

Remove "file://" from path...

FileInputStream file = new FileInputStream(new File(Environment.getExternalStorageDirectory().getPath()
                    + "/RegInfo/output/data.xml"));

Only using Environment.getExternalStorageDirectory().getPath(), you will get the SDCard directory. Theres no need to add "file://" before path.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download