gpt4 book ai didi

java - 文件存在时出现 FileNotFoundException

转载 作者:行者123 更新时间:2023-11-29 08:55:31 24 4
gpt4 key购买 nike

我收到 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)

但文件实际上存在,谁能帮忙吗

最佳答案

可能您没有读取此文件的权限。看这篇文章:

Get FileNotFoundException when initialising FileInputStream with File object

关于java - 文件存在时出现 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20466179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com