0

I am using classLoader to load xml files located under /src/XMLS :

String m_path = "XMLS/file.xml"

ClassLoader cl = getClass.getClassLoader();
file f1 = new file(cl.getResource(m_path).getFile));

Running on windows it works fine but after export to jar and running it on Linux I get FileNotFoundException - /XMLS/file.xml. I had tried this solutions and I dont think that the problem is in the read from the .jar file. any other ideas for what I am doing wrong?

Community
  • 1
  • 1
Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114

1 Answers1

2

This will not work for a resource inside a jar file, which is not a file on the filesystem. Instead, you need to use getResourceAsStream(), which returns an InputStream to use directly:

InputStream in = someClass.getClassLoader().getResourceAsStream("/XMLS/file.xml");
chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152