I've been scouring the web for a solution to this seemingly simple problem, but I always run into FileNotFoundException
. I am using Java 8 on Eclipse Oxygen and can't retrieve my txt
file from either absolute path or relative path. As suggested in other SO answers I got the path to the current directory, which I suppose is where the txt file is loaded from:
Path path = FileSystems.getDefault().getPath("").toAbsolutePath();
This showed my directory as E:\eclipse-java-oxygen-R-win32\HashMap
However, when I added my txt file to that project directory (containing src
,bin
directories) it still couldn't find the file when I wrote: Scanner input = new Scanner(new File("free.txt"))
I even tried the absolute path: Scanner input = new Scanner(new File("E://eclipse-java-oxygen-R-win32//HashMap//free.txt"));
I included a screenshot of the location of my free.txt file below.