XML 文件提取 - 相对路径不起作用
真的很累搜索,只是充斥着这样的问题。我正在尝试:
InputStream inputStream = DBconnection.class.getResourceAsStream("com.xxx.xxxxx.internal.props.xml");
Properties properties = new Properties();
properties.loadFromXML(inputStream);
抛出空指针异常
文件位于 com\xxx\xxxxx\internal\props.xml 下 我尝试过使用点、斜杠,我进行了搜索,我试图理解 - http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html?page=2 ,完全糊涂了。
Really tired to search, it's just flooded with these kind of problems. I am trying to:
InputStream inputStream = DBconnection.class.getResourceAsStream("com.xxx.xxxxx.internal.props.xml");
Properties properties = new Properties();
properties.loadFromXML(inputStream);
Throws me null pointer exception
File located under com\xxx\xxxxx\internal\props.xml
I've tried with dots, slashes, I did search, I tried to understand - http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html?page=2
, got completely confused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不尝试使用“/com/xxx/xxxxx/internal/props.xml”呢?或者,如果 DBConnection 与 xml 文件位于同一包中,则只是“props.xml”。
Why don't you try with "/com/xxx/xxxxx/internal/props.xml" instead. Or just "props.xml" if DBConnection resides in the same package as th xml file.