3.01.Properties类

2019-01-09  本文已影响0人  RockyLuo_290f

继承于hashtable,是线程安全的键值对存储结构

可保存在流中或从流中加载

只能保存字符串的键值对

public static void main(String[] args){
  Properties prop = new Properties();

  prop.setProperty("name", "zhangsan");
  prop.setProperty("age", "10");
}

将Properties存入到文件中


PrintWriter pw = null;
try{
  pw = new printWriter("out.txt");
  prop.list(pw);
}catch(IOException e){
  e.printStackTrace();
}finally{
  if(pw != null){
    pw.close();
  }
}
上一篇下一篇

猜你喜欢

热点阅读