搜索真的很累,到处都是这样的问题。我正在尝试:
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 ,完全糊涂了。
最佳答案
为什么不尝试使用“/com/xxx/xxxxx/internal/props.xml”呢?或者,如果 DBConnection 与 xml 文件位于同一包中,则只是“props.xml”。
关于java - XML 文件提取 - 相对路径不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7802883/