【发布时间】:2013-12-09 08:27:20
【问题描述】:
我收到 FileNotFoundException。但文件存在。
下面是代码:
try {
FileInputStream fis = new FileInputStream("conf/sampleprop.conf");
Properties prop = new Properties();
prop.load(fis);
String file = prop.getProperty("FILE");
System.out.println("File : " + file);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
输出是:
File : "C:\Chithra\Contacts.txt"
java.io.FileNotFoundException: "C:\Chithra\Contacts.txt" (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at PropertiesTest.main(PropertiesTest.java:32)
但是文件实际上已经退出了, 谁能帮忙
【问题讨论】:
-
这是在 Windows 上运行的吗?
-
在 Windows 中使用 eclipse 是的
-
给出完整的代码,包括“文件”的初始化
-
为什么你的文件名用双引号括起来?
-
删除双引号并将其作为 FILE = C:\Chithra\Contacts.txt 存储在属性文件中。属性值不应在双引号中使用
标签: java eclipse filenotfoundexception