java - Parse XML File within Jar -
I have trouble loading XML files inside my Java game. Here's where the file is located (eclipse From):
I'm researching, and apparently to use XML file in a JR file, I have to call
DocumentBuilder.parse (InputStream) The problem is that when I getResourceAsStre I try to get InputStream using am ("res / xml / items.xml") it always blank. How can I not tap it? I do not want to put my resort folder inside my "src" folder, but do I have to take something that I have to set up? What will be the correct string of path? Thanks!
Edit:
My code:
Try {DocumentBuilder db = dbf.newDocumentBuilder (); InputStream = Thread.currentThread () GetContextClassLoader (). GetResourceAsStream ("res / xml / items.xml"); Dom = db.parse (is); } Hold (exception e) {e.printStackTrace (); } It still makes me null.
< Div class = "post-text" itemprop = "text">
So, assuming that you ask Eclipse to use "res" as the source folder, there are still two problems in your lookup :
Item.class.getResourceAsStream ("res / xml / items.xml"); This is a relative path, so be sure to fill the getResourceAsStream () directory where Item.class remains (see). The other problem is that Eclipse considers the "source" folders as the root cause of your cell spaces. Then you need to change the path to exclude "race".
One option is to use a full path: "/ xml / items.xml" A better option Thread.currentThread () Have to call GetContextClassLoader (). GetResourceAsStream () , which will work correctly in an app-server as well as in the self-contained application (and to be included in this good habit) but you still have to leave "RAZ" on your own path.
Comments
Post a Comment