java - Loading xml from .jar -


i'm trying load .xml file .jar (made ant builder.xml) got exception.

code ant build.xml:

ant builder code

code class:

try { xml = new file(this.getclass().getresource("/taskdata.xml").getfile());     } catch (exception e) {         e.printstacktrace(); 

exception got:

java.io.filenotfoundexception: c:\users\agent_000\desktop\....file:\c:\users\agent_000\desktop\%d1%85%d1%83\build\sample.jar!\taskdata.xml ( 

why can't find .xml file?

thanks in advance!

you can this

    url url = new url("jar:file:/path--to-your jar !/taskdata.xml");     inputstream = url.openstream();     system.out.println(is);      bufferedreader reader = new bufferedreader(new inputstreamreader(is));     system.out.println(reader.readline()); 

or ask classloader return inputstream resource instead via getresourceasstream:

inputstream in = getclass().getresourceasstream("/taskdata.txt");  bufferedreader reader = new bufferedreader(new inputstreamreader(in)); 

Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -