public static void main(String[] args) throws IOException {
testWrite();
testRead();
}
private static void testWrite() throws IOException {
Properties p = new Properties();
p.setProperty("name", "shawearn");
p.setProperty("address", "XX 省 XX 市");
FileOutputStream out = new FileOutputStream("shawearn.properties");
p.store(out, "Create by Shawearn!");
out.close();
System.out.println("写入成功!");
}
private static void testRead() throws IOException {
Properties p = new Properties();
FileInputStream in = new FileInputStream("shawearn.properties");
p.load(in);
in.close();
Set<String> keys = p.stringPropertyNames();
for (String key : keys) {
Object value = p.get(key);
System.out.println(value);
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a354a0495e63d119fd653d1c8a96d407.png)