I posted a similar question here: Read from a file containing integers – java but couldn’t get a decent reply.
Now I have written this new code which only reads a file and outputs the result.
I get a FileNotFoundException whenever I try to read from a file. The code is below:
import java.io.*;
public class second {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File f = new File("C:\\Users\\Haroon\\workspace\\ppp\\temperature.txt");
FileReader file = new FileReader(f);
BufferedReader buf = new BufferedReader(file);
String s = null;
while((s = buf.readLine()) != null){
System.out.println(s);
}
}
}
This is strange because the file is in the project’s folder.
Any help would be appreciated.
That should work. Go to the location of the file, copy the path, paste it in your code, and escape the slashes. You are missing something.
Also check that the name/extension of the file is correct, you could have something like “temperature.txt.txt”.