Reputation: 49
I'm trying to scan a text file. Yes, I know... this is simple. I've been trying to locate the path of my text file and nothing works, it gives me a NoSuchFileException
for (String line : Files.readAllLines(Paths.get("/com/panda/anagramsolver/handling/word_list.txt"))) {
System.out.println(line);
}
The file I'm trying to scan is located at com.panda.anagramsolver.handling.word_list.txt. I know this question will get a lot of downvotes, I couldn't elaborate my question enough to find it on google. In advance, thanks.
Upvotes: 3
Views: 57
Reputation: 1101
The path starts with a /
. So unless you mean to search inside a directory named com
in your root directory, you will fail to locate the file.
You might want to try executing something like System.out.println(new File("."))
to find the location at which the program is executed, and then build up a relative path from that location. But at a more fundamental level, if the program is intended to work with that file always (i.e., if the file is a resource for the program), you might want to turn to Class#getResourceAsStream(). This link is to a tutorial.
Upvotes: 2