Quantcast
Channel: Where to put resources and access it in Java Project (in IntelliJ)? How to read from it then? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Where to put resources and access it in Java Project (in IntelliJ)? How to read from it then?

$
0
0

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!


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>