吕展辉

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Properties是java的Legacy Collections(遗留集合)属性映射表(property map)是一个类型非常特殊的映射表结构。它有下面3个特性:
• 键与值都是字符串。
• 表可以保存到一个文件中,也可以从文件中加载。
• 使用一个默认的辅助表。
实现属性映射表的Java平台类称为Properties。
属性映射表通常用于程序的特殊配置选项。

Properties类表示的是一个属性集(里面可以放置一些属性集),Properties可以保存在流中store(OutputStream,String)

File file = new File(//路径);
FileOutputStream fos = null;
fos = new FileOutputStream(file);
Properties properties = new Properties();
properties.store(fos,"comment");
fos.close();

或从流中加载load(InputStream)

FileInputStream fis = null;
File file = new File(//路径);
fis = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fis);
fis.close();

 

posted on 2014-02-12 14:29  吕展辉  阅读(496)  评论(0编辑  收藏  举报