Properties
package demo;
import java.util.Properties;
public class demo3 {
public static void main(String[] args) {
Properties properties = new Properties();
properties.setProperty("username","zhangsan");
properties.setProperty("age","20");
System.out.println(properties.toString());
System.out.println("___________________");
System.out.println(properties.keySet());
System.out.println("___________________");
System.out.println(properties.entrySet());
}
}
运行结果
{age=20, username=zhangsan}
___________________
[age, username]
___________________
[age=20, username=zhangsan]
Process finished with exit code 0
与流有关的方法
// 与流有关的方法
// _____list_____
PrintWriter pw = new PrintWriter("d:\\print.txt");
properties.list(pw);
pw.close();
// __________store保存 ——————————————————
FileOutputStream fos = new FileOutputStream("d:\\store.properties");
properties.store(fos,"注释");
fos.close();
// _____load加载_____
Properties properties1 = new Properties();
FileInputStream fis = new FileInputStream("d:\\store.properties");
properties1.load(fis);
fis.close();
System.out.println(properties1.toString());