java.io.FileNotFoundException,找不到文件 [英] java.io.FileNotFoundException, file not being found

查看:478
本文介绍了java.io.FileNotFoundException,找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想逐行阅读一个文件。
这是为了简单,但我不能把它正确!

  String fileName =C :/Users/Diogo/Desktop/Krs_Grafo/Graph.txt; 
FileReader file = new FileReader(fileName);
BufferedReader inputStream = new BufferedReader(file);
System.out.println(inputStream.readLine());

我不断收到错误:

 线程main中的异常java.io.FileNotFoundException:C:\Users\Diogo\Desktop\Krs_Grafo\Graph.txt(O sistemanãopode encontrar o arquivo especificado) 
在java.io.FileInputStream.open(本地方法)
在java.io.FileInputStream。< init>(FileInputStream.java:120)
在java.io.FileInputStream。< ; init>(FileInputStream.java:79)
at java.io.FileReader。< init>(FileReader.java:41)
at krs_grafo.Krs_Grafo.main(Krs_Grafo.java:51)
Java结果:1

系统无法找到文件,但我确定它在那里!
我在Windows 7上使用Netbeans 7.0。

$ p
$ b

在评论中,它正在搜索Graph而不是Graph.txt。这是从以前的执行,我没有扩展尝试。所以,我编辑它是连贯的。它仍然不起作用。

解决方案

这里的问题是文件名实际上是 Graph.txt。 txt ,因为扩展名被隐藏,所以我看不到。

感谢用户Michael Brewer-Davis在评论中询问在给定的目录中输出cd和dir。

同时指出/和\\工作得很好。


I just wanted to read a file line by line. This was meant to be simple, but i just can't get it right!

String fileName = "C:/Users/Diogo/Desktop/Krs_Grafo/Graph.txt";
FileReader file = new FileReader(fileName);
BufferedReader inputStream = new BufferedReader(file);
System.out.println(inputStream.readLine());

i keep getting the error:

Exception in thread "main" java.io.FileNotFoundException: C:\Users\Diogo\Desktop\Krs_Grafo\Graph.txt (O sistema não pode encontrar o arquivo especificado)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
at java.io.FileReader.<init>(FileReader.java:41)
at krs_grafo.Krs_Grafo.main(Krs_Grafo.java:51)
Java Result: 1

The system cant find the file, but i'm sure as hell it is there! I'm using Netbeans 7.0 on a Windows 7.

Any suggestions?

AS SAID IN THE COMMENTS, it was searching for "Graph" and not "Graph.txt". This was from a previous execution where I tried without the extension. So, I edited it to be coherent. It still doesn't work.

解决方案

The problem here is that the file name was actually "Graph.txt.txt" wich I couldn't see because the extensions were hidden.

Thanks to user "Michael Brewer-Davis" who asked in the comments for "output of cd and dir in the given directory".

Also point out that either / and \\ work just fine.

这篇关于java.io.FileNotFoundException,找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆