System nie może znaleźć pliku określonego w java
Tworzę program, który otwiera i odczytuje plik. To jest mój kod:
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());
}
}
}
ale kiedy uruchamiam, otrzymuję ten błąd:
C:\Users\User\Documents\Workspace\FileRead\hello.txt
Error: hello.txt (The system cannot find the file specified)
mójFileRead.java
ihello.txt
gdzie w tym samym katalogu, który można znaleźć w:
C:\Users\User\Documents\Workspace\FileRead
Zastanawiam się, co robię źle?