从SD卡读取文件时出现异常

Add*_*ddy 2 android ioexception android-sdcard

我试图从SD卡读取XML文件.路径很好,但它说:

java.io.FileNotFoundException:/file:/mnt/sdcard/Reginfo/output/data.xml(没有这样的文件或目录)

以下是我尝试阅读此文件的方法:

FileInputStream file = new FileInputStream(new File("file://"
                    + Environment.getExternalStorageDirectory()
                    + "/RegInfo/output/data.xml"));
Run Code Online (Sandbox Code Playgroud)

我可以sdCard/RegInfo/output在文件资源管理器中的文件夹中看到此文件.

Ham*_*atu 6

"file://"从路径中移除......

FileInputStream file = new FileInputStream(new File(Environment.getExternalStorageDirectory().getPath()
                    + "/RegInfo/output/data.xml"));
Run Code Online (Sandbox Code Playgroud)

只有使用Environment.getExternalStorageDirectory().getPath(),您将获得SDCard目录.没有必要"file://"在路径之前添加.