El sistema no puede encontrar el archivo especificado en java.
Estoy haciendo un programa que abre y lee un archivo. Este es mi código:
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());
}
}
}
pero cuando corro, me sale este error:
C:\Users\User\Documents\Workspace\FileRead\hello.txt
Error: hello.txt (The system cannot find the file specified)
miFileRead.java
yhello.txt
donde en el mismo directorio que se puede encontrar en:
C:\Users\User\Documents\Workspace\FileRead
Me pregunto qué estoy haciendo mal.