I am trying to read from a file using Java. But it shows an error saying that system cannot find the specified file, when the file is lying in the same directory as the source file.
below is the code:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class file
{
public static void main(String[] args) {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("RoomList.txt"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null) br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
I tried all I could but it just doesn't work. Please let me know the reasons for this. Again I will add that the file RoomList.txt and this code file are in the same directory and even after using fully qualified pathname, it doesn't work. I looked for similar answers for this problem in Stackoverflow and tried them but still it does not seem to be working. Please help.