在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");