import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
class PropertiesTest {
public static void main(String args[]){
Properties properties = new Properties();
String projectPath = System.getProperty("user.dir");
String propertiesPath = projectPath + File.separator + "resources" + File.separator + "first.properties";
try {
InputStream in = new FileInputStream(propertiesPath);
//不要忘记导入properties
properties.load(in);
System.out.println(properties.getProperty("key1"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
资源文件为 resources文件夹下的first.properties.内容:
key1 = properties test
输出结果: properties test