import java.io.InputStream;
import java.util.Properties;
public class PropertiesTest {
public static void main(String[] args) {
try {
InputStream personInfoInputStream = PropertiesTest.class.getClassLoader().getResourceAsStream("TestNewProperties.properties");
Properties personInfoProperties = new Properties();
personInfoProperties.load(personInfoInputStream);
System.out.println("属性文件中的姓名为" + personInfoProperties.getProperty("name"));
System.out.println("属性文件中的年龄为" + personInfoProperties.getProperty("age"));
System.out.println("属性文件中的地址为" + personInfoProperties.getProperty("address"));
System.out.println("属性文件中的工作为" + personInfoProperties.getProperty("job"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.Properties;
public class PropertiesTest {
public static void main(String[] args) {
try {
InputStream personInfoInputStream = PropertiesTest.class.getClassLoader().getResourceAsStream("TestNewProperties.properties");
Properties personInfoProperties = new Properties();
personInfoProperties.load(personInfoInputStream);
System.out.println("属性文件中的姓名为" + personInfoProperties.getProperty("name"));
System.out.println("属性文件中的年龄为" + personInfoProperties.getProperty("age"));
System.out.println("属性文件中的地址为" + personInfoProperties.getProperty("address"));
System.out.println("属性文件中的工作为" + personInfoProperties.getProperty("job"));
} catch (Exception e) {
e.printStackTrace();
}
}
}