java io找不到文件,java.io.FileNotFoundException,找不到文件

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.(FileInputStream.java:120)

at java.io.FileInputStream.(FileInputStream.java:79)

at java.io.FileReader.(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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值