在java中,可以用
java 代码
- Properties p = new Properties();
- InputStream is = this.getClass().getResourceAsStream(propertiesFileName);
- p.load(is);
- is.close;
来读取。
如果properties文件是在classpath的根目录下,如test.properties在src目录下,则可以这样读取:
- InputStream is = this.getClass().getResourceAsStream("test.properties");
如果不在要目录下,则要加上相对于classpath要目录的路径。如在src目录下,有一个包com.myapp.resources,则可以如下读取:
- InputStream is = this.getClass().getResourceAsStream("/com/myapp/resources/test.properties");
本文介绍了如何使用Java读取不同位置的properties文件,包括位于classpath根目录下的文件以及位于特定包内的文件。

被折叠的 条评论
为什么被折叠?



