Shaaf's blog

A technical blog about Java, Kubernetes and things that matter

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.

 	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 “/”