0

My project strrcture

I am trying to read pws.csv in the resources directory with this line:

BufferedReader br = new BufferedReader(new InputStreamReader(App.class.getClass().getResourceAsStream("pws.csv")));

When I try to run it in IntelliJ or the comiled jar, I get a NullPointerExceptions, which I understand means that the file cannot be found. I also tried variations on the path like "/pws.csv" and "src/main/resources/pws.csv" and got the same error. My understanding is, that when using maven, "src/main/resources" is a special directory and intelliJ will recognize it, when searching for resources do I have to change some setting to achieve this or am I just stupid ?

Edit: Listing of the jar:

Listing of the jar

Stacktrace of running that jar:

Exception in thread "main" java.lang.NullPointerException
    at java.base/java.io.Reader.<init>(Reader.java:167)
    at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:72)
    at com.kolan.Main.main(Main.java:8)
Connor Kolan
  • 81
  • 2
  • 9

1 Answers1

0

Put pwc.csv in a folder that is on the classpath. And of course, double check your classpath setting.

Stu
  • 15
  • 8