If it is already in the classpath and in the same package, use
URL url = getClass().getResource("b.xml");
File file = new File(url.getPath());
OR , read it as an InputStream
:
InputStream input = getClass().getResourceAsStream("b.xml");
Inside a static
method, you can use
InputStream in = YourClass.class.getResourceAsStream("b.xml");
If your file is not in the same package as the class you are trying to access the file from, then you have to give it relative path starting with '/'
.
ex : InputStream input = getClass().getResourceAsStream
("/resources/somex.cfg.xml");which is in another jar resource folder