Properties持久的属性集
来源:互联网 发布:知乎热门话题 编辑:程序博客网 时间:2024/06/03 06:43
Properties 属性集合继承了Hashtable
属性包括属性名和属性值(键值对key==value)
作用
- 可以存储多个键值,与map相似
- 可以把键值对存储到文件中
- 可以把文件中的键值对读取到Properties对象中
构造方法:
Properties() 创建一个无默认值的空属性列表。
成员方法:
- String getProperty(String key) 用指定的键在此属性列表中搜索属性。
- String getProperty(String key, String defaultValue) 用指定的键在属性列表中搜索属性。
- void load(InputStream inStream) 从输入流中读取属性列表(键和元素对)。
- void store(OutputStream out, String comments) 以适合使用 load(InputStream) 方法加载到 Properties 表中的格式,将此 Properties 表中的属性列表(键和元素对)写入输出流。comments是注释的内容
Object setProperty(String key, String value) 调用 Hashtable 的方法 put。添加键值对的方法,和map的put方法类似。
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.IOException;import java.util.Properties;public class PropertiesDemo {public static void main(String[] args) throws IOException { Properties pros = new Properties(); read(pros);}public static void read(Properties pros) throws IOException, FileNotFoundException { pros.load(new FileInputStream("a.properties")); System.out.println(pros.get("哈哈哈")); System.out.println(pros); System.out.println("输入成功");}public static Properties add() throws FileNotFoundException, IOException { //创建一个空的属性列表 Properties pros=new Properties(); System.out.println(pros); //添加键值对 pros.setProperty("哈哈哈", "呵呵呵"); pros.setProperty("喔喔", "方法"); pros.setProperty("宿舍的", "付款"); //通过key 来获取值 String value1 = pros.getProperty("哈哈哈"); String value2 = pros.getProperty("喔喔"); System.out.println(value1); System.out.println(value2); //将properties写入到文件中 FileOutputStream fos=new FileOutputStream("a.properties"); pros.store(fos, "我是注释 comments"); return pros; } }
阅读全文
0 0
- Properties 持久的属性集
- Properties持久的属性集
- Properties属性持久化
- Properties属性持久化
- System.Properties的属性
- 获取Properties的属性
- DirectoryEntry.Properties属性的遍历
- 【JAVA基础】本地持久化的非数据库方式:properties
- Quartz存储与持久化-基于quartz.properties的配置
- Properties属性
- 属性 (Properties)
- struts2的struts.properties的属性介绍
- 读取.properties属性文件--今天的郁闷
- DirectoryEntry.Properties属性的遍历,非常棒
- C# 3.0 的自动属性(Automatic Properties)
- Qt的属性Properties例子代码
- C# 3.0 的自动属性(Automatic Properties)
- C# 3.0 的自动属性(Automatic Properties)
- [欧拉函数]51nod 1188 最大公约数之和 V2 题解
- 新能源对话工坊第一期:中国将迎来混合动力车爆发年?
- 驱动安装需要数字签名导致安装失败的解决方法
- SNH48与手机管家合作来电秀 圣诞送好礼
- python 删除字符串中的空格
- Properties持久的属性集
- 资本寒冬下看极米科技如何两年获得4亿融资
- 开始复习下js了
- 每日产品辣评:华仔代言的金品质立天下,这次请来了Beyond
- java框架总结之struts2:
- 每日产品辣评:重量8g售价4万美元,比黄金还贵几十倍的东西是什么鬼?
- 腾讯众创空间明年要孵化100个项目 潘石屹为创业者破戒
- 数据结构实验之栈与队列二:一般算术表达式转换成后缀式
- xml(1)