【发布时间】:2016-08-15 12:48:40
【问题描述】:
我在项目的根目录 (Player.xml) 创建了一个 xml 文件。我在 AndroidManifest.xml 中添加了使用权限标签。我觉得我已经尝试了一切,但仍然得到 FileNotFoundException。 我在 onCreate() 方法中的代码:
try {
String newFile = "/TTBossUI/Player.xml";
FileInputStream inputStream7;
File f = new File(newFile);
System.out.println("made it to pos #1");
inputStream7 = new FileInputStream(f);
System.out.println("made it to pos #2");
inputStream7.close();
System.out.println("made it to pos #3");
} catch (FileNotFoundException fnfe) {
System.out.println("file not found:" + fnfe);
return;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我从来没有超过“到达 pos #1”,直接进入 catch 块。 我已经尝试了所有可能的文件/文件路径字符串。 我在仅 Java(非 android)应用程序中完美运行。 提前致谢!
【问题讨论】:
-
您收到的错误是什么?请分享logcat
-
这是来自 LogCat 的相关信息:到达 pos #1 08-15 13:08:26.049: I/System.out(797): file not found: java.io.FileNotFoundException: /TTBossUI/Player.xml:打开失败:ENOENT(没有这样的文件或目录)
-
到达 pos #1 08-15 13:08:26.049: I/System.out(797): file not found: java.io.FileNotFoundException: /TTBossUI/Player.xml: open失败:ENOENT(没有这样的文件或目录)
-
请不要在 cmets 中发布日志输出或代码!改为编辑问题并在其中添加信息。
标签: android io filenotfoundexception fileinputstream