I currently have a project in Java set up with the following directory structure in Eclipse:
And in my code I have the following lines:
InputStream is = this.getClass().getClassLoader().getResourceAsStream("resources/config");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
However, the InputStream is
always gets assigned to null, which causes a crash when it gets to the second line. I know it has something to do with how I set up the path that it's looking for, but I can't figure out exactly why it isn't working.
Your config
file is in your project, somewhere on the file system.
However, Eclipse isn't putting it on the classpath. To force it to be on the classpath, right click your folder and add it as a source folder. Eclipse will then add it to the root of the classpath. You can retrieve it with
InputStream is = this.getClass().getResourceAsStream("/config");
Eclipse puts everything in resources
source folder starting at the root of the classpath. Therefore
resources/config
will appear in classpath as
/config
/qbooksprintfix/FileChecker
/qbooksprintfxi/FilePurgeHandler
/...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With