How do I read a resource file from a Java jar file?

后端 未结 9 1750
遥遥无期
遥遥无期 2020-11-22 09:22

I\'m trying to access an XML file within a jar file, from a separate jar that\'s running as a desktop application. I can get the URL to the file I need, but when I pass tha

9条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 10:07

    The problem was that I was going a step too far in calling the parse method of XMLReader. The parse method accepts an InputSource, so there was no reason to even use a FileReader. Changing the last line of the code above to

    xr.parse( new InputSource( filename ));
    

    works just fine.

提交回复
热议问题