Егор Лебедев Егор Лебедев - 12 days ago 6
Java Question

Java: file not found exception

File file1 = new File("news1.txt");
System.out.println(file1.exists());


This prints false, but file
news1.txt
is in directory, with that class.

Answer

This assumes that news1.txt is in the same folder as the class, calling this code. If you are using Eclipse, for example, this will look for the file in the root folder of the project, and not in the src folder. You should verify that the file is indeed in the right location.