我使用上述方法感到困惑,因为在加载某些属性文件时,人们正在遵循不同的方法......
Properties prop
= new Properties(new FileInputStream(new File("<path of the properties file>"));
Run Code Online (Sandbox Code Playgroud)
很少有人在使用..
Properties prop
= new Properties(getClass().getResourceAsStream("<path of the properties file>"));
Run Code Online (Sandbox Code Playgroud)
哪一个使用的时候?
getResourceAsStream搜索给定文件/资源的类路径,它还可以InputStreams从JAR内部提供资源.
因此,如果您的属性存在于物理文件系统中的某个文件夹中(例如用户文件夹,...),请使用FileInputStream并且如果该文件嵌入在您的类路径中(例如作为JAR内的资源)使用getResourceAsStream.
| 归档时间: |
|
| 查看次数: |
2968 次 |
| 最近记录: |