Opening a xml file from eclipse and from a .jar file in java -


yesterday, had problem because couldn't manage open xml file (it owuld give me filenotfoundexception) located in ressources folder of .jar file, managed open on eclipse using following lines of code. can see old problem here. code problem :

file xmlfile = new file("ressources/emitter.xml"); configurableemitter emitter = particleio.loademitter(xmlfile); 

someone told me 1 way use getclassloader().getressourceasstream method open xml file in .jar file exported

inputstream i= this.getclass().getclassloader().getresourceasstream("ressources/emitter.xml"); configurableemitter emitter = particleio.loademitter(i); 

unfortunately, solution works when export project .jar file, if want go debugging program, have take old code works on eclipse.

my question is: there better way without having change code if want export or if want debug it?

thank you

edit : thank all, works fine problem put ressources folder :

+project    +src    +ressources      +emitter.xml 

inputstream i= this.getclass().getclassloader().getresourceasstream("/ressources/emitter.xml"); 

the above should work in both cases (note is /resources/.... assuming directory structure below:

myproject

+src     +ressources          emitter.xml 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -