Loading XML File which is in classpath in Java

主宰稳场 提交于 2019-12-10 13:47:23

问题


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

Thanks,
Narendra


回答1:


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.)



来源:https://stackoverflow.com/questions/4264594/loading-xml-file-which-is-in-classpath-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!