Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 文件存在时FileNotFoundException_Java_Eclipse_Filenotfoundexception - Fatal编程技术网

Java 文件存在时FileNotFoundException

Java 文件存在时FileNotFoundException,java,eclipse,filenotfoundexception,Java,Eclipse,Filenotfoundexception,我收到一个FileNotFoundException。但是文件存在 代码如下: try { FileInputStream fis = new FileInputStream("conf/sampleprop.conf"); Properties prop = new Properties(); prop.load(fis); String file = prop.getProperty("FILE");

我收到一个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)
文件:“C:\Chithra\Contacts.txt”
java.io.FileNotFoundException:“C:\Chithra\Contacts.txt”(文件名、目录名或卷标语法不正确)
在java.io.FileInputStream.open(本机方法)
位于java.io.FileInputStream。(未知源)
位于java.io.FileInputStream。(未知源)
位于java.io.FileReader。(未知源)
位于PropertiesTest.main(PropertiesTest.java:32)
但是文件确实存在,
有人能帮忙吗

也许你没有阅读此文件的权限。见此帖:


尝试将文件名设置为“C:/Chithra/Contacts.txt”


在java中不要使用“\”,java读取以“/”

分隔的文件路径这在Windows上运行吗?在Windows中使用eclipsegive完整代码(包括“文件”的初始化)是的,为什么文件名用双引号括起来?删除双引号,并将其存储为属性文件中的file=C:\Chithra\Contacts.txt。属性值不应在双引号中使用,但我在Windows机器中使用eclipse运行,并使用canRead()和来自File类的isFile()方法创建了txt fileTry。请参阅提供的链接中的第一个答案。写入文件后是否关闭了编写器?