문제

I am trying to read an XML file from the SD card. The path is fine, but it says:

java.io.FileNotFoundException: /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 sdCard/RegInfo/output folder in File Explorer.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top