我正在使用Maven进行项目.在我的一个java类中,我需要获取一个属性文件.我不能使用绝对文件位置而是相对路径.我尝试了几种方法,但没有运气.
java在
myProject/src/main/java/com/some/myConfiguration.java
Run Code Online (Sandbox Code Playgroud)
属性文件位于
myProject/src/main/com/some/resources/myProperties/myFeatures.properties
Run Code Online (Sandbox Code Playgroud)
在我的java中,我有一些像这样的代码
String filePath = "correct/path/to/myFeatures.properties";
File repositoryFile = new File(filePath);
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我应该给予的 filePath
谢谢你的任何建议.
myFeatures.properties属性文件放入其中src/main/resources使用以下命令在Java代码中访问它:
this.getClass().getClassLoader().getResourceAsStream("myFeatures.properties");
| 归档时间: |
|
| 查看次数: |
5606 次 |
| 最近记录: |