系统找不到java_系统找不到在java中指定的文件

我正在制作一个打开并读取文件的程序。

这是我的代码:

import java.io.*;

public class FileRead{

public static void main(String[] args){

try{

File file = new File("hello.txt");

System.out.println(file.getCanonicalPath());

FileInputStream ft = new FileInputStream(file);

DataInputStream in = new DataInputStream(ft);

BufferedReader br = new BufferedReader(new InputStreamReader(in));

String strline;

while((strline = br.readLine()) != null){

System.out.println(strline);

}

in.close();

}catch(Exception e){

System.err.println("Error: " + e.getMessage());

}

}

}

但是当我运行,我得到这个错误:

C:\Users\User\Documents\Workspace\FileRead\hello.txt

Error: hello.txt (The system cannot find the file specified)

我的FileRead.java和hello.txt在同一目录中可以找到:

C:\Users\User\Documents\Workspace\FileRead

我想知道我做错了什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值