I am trying to read a file from the hard disk in java. However when I am trying to: BufferedReader inputReader = new BufferedReader(new FileReader("weather.txt"));
and I'm receiving the following message:
Exception in thread "main" java.io.FileNotFoundException: C:\weather.txt (System cannot define the specific file) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.(FileInputStream.java:138) at java.io.FileInputStream.(FileInputStream.java:93) at java.io.FileReader.(FileReader.java:58)
I tried to change the location of the file many times. However I got the same error. The location of the file is C:\weather.txt
. What I am missing here?
EDIT: Based on the proposed answer I tried to do the following:
File targetFile = new File("C:\\", "weather.txt");
FileReader fr = new FileReader(targetFile);//BufferedReader datafile = readDataFile("C://weather.txt");
BufferedReader br = new BufferedReader(fr);
It seems that I cant use at all bufferedReader. What is happening here?