开发者

Loading XML File which is in classpath in Java

开发者 https://www.devze.com 2023-01-27 05:08 出处:网络
I need to load a xml file present in classpath into my java applicatio. Can any one give suggestions on this.

I need to load a xml file present in classpath into my java applicatio. Can any one give suggestions on this.

Thanks,

Narendra开发者_如何学运维


Use ClassLoader.getResourceAsStream or Class.getResourceAsStream, and then load it as you would for any other InputStream.

(The difference between using the ClassLoader version and the Class version is how "relative" resource paths are resolved. With the ClassLoader version, it's always effectively treated as an absolute path; with the Class version, if the path doesn't start with "/" it's treated as relative to the package of that class.)

0

精彩评论

暂无评论...
验证码 换一张
取 消