In the following the code I keep getting the error “(No such file or directory)”
public void readFile() throws IOException {
reader = new BufferedReader(new FileReader("map1.txt"));
while(true) {
String line = reader.readLine();
System.out.println(line);
if(line == null) {
reader.close();
break;
}
}
}
I get this same error when I try to read images / anything really. But in the examples I’ve seen of how to use file readers they all just put in the name of the files and nothing else. In this case the map is in a separate folder in the src file called Maps. I’ve tried various specifications of “/Maps/map1.txt” but nothing seems to work. How do I get this file to read?
(I’m on a mac as well. I don’t know if that changes things.)
Update
Seems like it is netBeans’ fault. It only looks the project folder. I think I’ll start another topic asking how to remedy this later. Thank you for all the help everyone.
I assume you have a folder named
srcwhich has your java files; in this same folder there is a folder namedMapswhich hasmap1.txt.Now,
Is going to to try to open the file map1.txt in the current directory. Which directory this is depends on the IDE you use; but you should be able to change it.
If you change it to the folder which has the file it should work.