java - reading xml file from jar -
I am trying to deploy a XML configuration from a jar file to a DM-server
Here is the code
Reader FileRadder = Faucet; {Try FileReader = New FileReader ("test.xml"); } Catch (filenoutfound expense FNFX) {fnfex.printStackTrace (); } Hold (IOException ioex) {ioex.printStackTrace (); }
I was able to read it if I just write a junit test w / o jar and w / o DM-server.
The test pack is in the jar and the jar is in the root of the file.
Please help !!!!
Thank you, A
You get the getResource
Or getResourceAsStream
methods need to be used to read files from within the jars.
This can be done like this:
Reader filereader = faucet; InputStream = this.getClass (). GetResourceAsStream ("/ test.xml"); If (empty! =) {FileReader = new input screen reader (); }
Note that getResourceAsStream
returns zero if the file can not be found.
Edit: test.xml is correct in / test. Xml
Also keep in mind that class
or as appropriate.
Comments
Post a Comment