PropertyReaderTest.java文件:
package com.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertyReaderTest {
public static void readProperties(){
InputStream in = PropertyReaderTest.class.getResourceAsStream("test.properties");
Properties p = new Properties();
try {
p.load(in);
System.out.println("名字:"+p.get("testName"));
System.out.println("密码:" + p.get("testPass"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println("读取properties");
PropertyReaderTest.readProperties();
}
}
test.properties 文件
testName=zhangsan
testPass=123456