java - Read XML file from containing JAR -


i trying read xml file inside of jar.

my folder structure this:

[root]       src (source folder)           [my java files]     res (source folder)         xml             lorem_ipsum.xml (xml file wish read) 

and i'm trying use code read file:

documentbuilderfactory dbfac = documentbuilderfactory.newinstance(); documentbuilder db = dbfac.newdocumentbuilder(); classloader cl = thread.currentthread().getcontextclassloader(); inputstream stream = cl.getresourceasstream(path);  if(stream == null) {     return null; }  document doc = db.parse(stream); 

but it's not working. stream keeps on being null when specifiy /xml/lorem_ipsum.xml path.

based on posted directory structure...

[root]       src (source folder)           [my java files]     res (source folder)         xml             lorem_ipsum.xml (xml file wish read) 

res doesn't seem embedded resource. instead try using new file("res/xml/lorem_ipsum.xml") instead of trying inputstream classes resource context


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -