Shaaf’s Blog
msgbartop
Another bit in the wall
msgbarbottom

31 Oct 08 How to read a file from the JAR?

Someone just asked me this question today. And I thought might as well put it down for info.

1
2
3
4
 public TestReadFileFromJar() throws FileNotFoundException, IOException {
        InputStream is = getClass().getResource("txtData/states.properties");
        read(is);
}

In the case above txtData is placed in the jar on the root. Remmember to add the path with the /

Tags: , , , , , , ,