I have a txt file. I have packaged it in a zip and a jar, using jar cf0.... I have tried both in an effort to get this to work.
models.zip/models.jar
|
|_subfolder
|
|_MyFile.txt
In some code I have…
InputStream in = getClass().getClassLoader().getResourceAsStream(path);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
I have tried setting path to…
MyFile.txt
/MyFile.txt
/subfolder/MyFile.txt
classpath:/subfolder/MyFile.txt
models.zip/subfolder/MyFile.txt
models.jar/subfolder/MyFile.txt
models.zip!/subfolder/MyFile.txt
models.jar!/subfolder/MyFile.txt
I have also tried putting the jar/zip in WEB-INF/classes and WEB-INF/lib.
None of this works, in is always null.
And just so you know, when I put MyFile.txt in WEB-INF/classes I can get it fine.
Please provide a tried and tested answer! Please dont just copy and paste code from another answer.
I feel like a plonker! Problem was having models.jar in both the lib AND the classes folder. It should be in just the lib folder.