我得到一個FileNotFoundException。但該文件存在。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 – user1407668
給出完整代碼,包括「文件」的初始化 – TheLostMind