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: HOWTO, jar, Java, Programming, Software, Software Development, tips, utils
If you are using spring i would use
import org.springframework.util.ResourceUtils;
File file = ResourceUtils.getFile(“classpath:txtData/states.properties”);
hope this helps