Система не может найти файл, указанный в 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
Мне интересно, что я делаю не так?