目录结构如下
test.priperties如下
GetProperties.java代码如下
package util;
import java.io.IOException;
import java.util.Properties;
public class GetProperties {
public static void main(String[] args) {
Properties prop = new Properties();
try {
prop.load(GetProperties.class.getClassLoader()
.getResourceAsStream(
"test.properties"));
} catch (IOException e) {
e.printStackTrace();
}
String fileName=prop.getProperty("fileName");
String path=prop.getProperty("path");
System.out.println("fileName="+fileName);
System.out.println("path="+path);
}
}
控制台输出