本文介绍了加载Java类路径中的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将类路径中存在的xml文件加载到我的Java应用程序中。

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

谢谢,

Narendra

Thanks,
Narendra

推荐答案

使用或,然后按需加载对于任何其他 InputStream

(使用 ClassLoader 版本和 Class 版本是解决相对资源路径的方式,而 ClassLoader 版本是总是有效地视为绝对路径;对于 Class 版本,如果路径不是以 /开头,则将其视为相对于该类包的路径。)

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

这篇关于加载Java类路径中的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:20
查看更多