Properties
配置文件,很多是用 .properties 的
存储的方式,是键值对,类似于下面的形式
键=值
存
public static void main(String[] args) throws IOException {
Properties ppt = new Properties();
//在内存中,存入数据
ppt.put("name","金苹果");
ppt.put("desc","讲述了苹果种植的辛酸历程");
//使用字符输出流,写出
FileWriter fw = new FileWriter("/Users/faro_z/Documents/测试路径/testDir/books.properties");
// 这里写的是注解
ppt.store(fw,"存储的图书");
fw.close();
}
取
public static void main(String[] args) throws IOException {
Properties ppt = new Properties();
//使用字符输入流,写入
FileReader fr = new FileReader("/Users/faro_z/Documents/测试路径/testDir/books.properties");
ppt.load(fr);
String name = ppt.getProperty("name");
String desc = ppt.getProperty("desc");
System.out.println(name);
System.out.println(desc);
}