在创建 jar 文件时将 XML 文件放在 Netbeans 目录结构中的哪个位置
在 Netbeans IDE 中,我正在编写一个具有某些方法的 java 类。一种方法读取我放在 src/resources 文件夹中的 xml 文件。为了访问此 xml,我使用路径“src/resources/xmlFile.xml”。当我从 ID 运行该类时,它工作正常。没问题。
但我用类创建了 xml 文件的 jar。这个jar与其他一些项目一起使用这次方法无法读取xml文件。
我应该使用什么相对路径以便该方法能够读取 xml?或者还有什么其他解决方案?
谢谢
In Netbeans IDE i am writing a java class which has some method. One method reads a xml file that I put in the src/resources folder. To access this xml I use the path "src/resources/xmlFile.xml". When I run the class from the ID It works fine. No problem.
But I create the jar of the xml file with the classes. This jar is used with some other project This time method is unable to read the xml file.
What relative path I should use so the method will be able to read the xml? or what other solution could be?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅此答案:
读取类路径中的文件
See this answer:
read file in classpath