I have text file, which I want to read from, but I don`t really know how to navigate from the class path to the path where the file is.
This is my project structure:Project structure photo(Intellij)
public class Main { public static void main(String[] args) { URL fileURL = Main.class.getResource("resources/coding_qual_input.txt"); if (fileURL != null) { File file = new File(fileURL.getFile()); try { BufferedReader in = new BufferedReader(new FileReader(file)); }catch (FileNotFoundException e) { e.printStackTrace(); } } }}
I don't really know, if put the file correctly, but right now the new FileReader(file)
gets me null
.
So, why can't the FileReader
read my file?
As Main.class.getResource("resources/coding_qual_input.txt")
results in file:/C:/Users/Jonas/IdeaProjects/Android%20ATC/pyramidDecoder/out/production/pyramidDecoder/resources/coding_qual_input.txt
, I don't see where the problem is.
Should I navigate somehow down the classpath?
Thanks for the help!