![](/img/trans.png)
[英]I think i'm hitting an infinite loop somewhere in my java Mandelbrot program
[英]Does my Java Virtual Machine think that I'm under unix even when I'm on windows?
我对在Logcat中获得的结果感到困惑。 我正在尝试读取文件,但出现FileNotFoundException。 现在,我正在对文件所在的URL进行硬编码。
InputStream readMyFile(String fileName){
File file = new File("C:\\Users\\Alvaro\\workspaceEclipse\\ProyectA\\file.xml");
//File file = new File("C:" +File.separator +"Users" +File.separator +"Alvaro" +File.separator +"workspaceEclipse" +File.separator +"ProyectA" +File.separator +"file.xml");
System.out.println("Working Directory = " +
System.getProperty("user.dir"));
System.out.println(file.exists());
System.out.println(file.canRead());
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
if (in != null) {
in.close();
}
}catch(Exception e){
System.out.println("Error opening the file. \n" +e);
}
return in;
}
我可以看到找不到该文件,因为以某种方式在URL字符串的开头插入了一个“ /”:
/C:\Users\Alvaro\workspaceEclipse\ProyectA\file.xml: open failed: ENOENT (No such file or directory)
问题是,如果我使用File.separator,则输出为:
/C:/Users/Alvaro/workspaceEclipse/ProyectA/file.xml: open failed: ENOENT (No such file or directory)
有谁知道可能会发生什么?
其他信息:
我认为问题在于您并未真正在“ Windows上”运行。
相反,我怀疑您是在Android仿真环境中运行。 Android是专为Linux设计的,我希望仿真环境中的Android运行时库假定文件系统使用UNIX / Linux样式的路径名。
赠送的是您在logcat中看到消息。 Logcat是Android风格的。 它不是Windows上的Java或Linux上的Java的本机。
还要注意的另一件事是,您尝试执行的操作(访问Eclipse工作区中的文件)并不是在真正的Android设备上可以使用的。 与其弄清楚如何使用Windows路径名访问Eclipse工作区,不如弄清楚如何将文件放入Android应用程序本身或(模拟的)Android文件系统中。
如果要确认此诊断,请获取代码示例并将其放入纯Java应用程序中,然后在命令提示符下进行编译和运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.