Our favorite development tool, Eclipse, makes it slightly confusing to read files properly inside of a Java program.
To start with, I make a file as anyone would, just a quick right click in the Project Tree, then New and finally to File as in a blank file.One would assume that a non-java would exist in the top-level directory of the project instead of binsrc. However, something fishy happens though. If you try, inside your program, to reference your new file, you might try,
input.txt. Does that work? No.
So here’s the scary error you get when you try to run a basic program, just reading a file into an array line-by-line.
Exception in thread “main” java.io.FileNotFoundException: input.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
Good people at StackOverflow leave us the answer.
Yeah, eclipse sees the top directory as the working/root directory, for the purposes of paths.
So, basically, if you have a file called input.txt, you can actually find in-program via src/input.txt. Why does Eclipse not make this path-reality more clear?