Properties属性操作
package com.properties; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; /** * Properties:Hashtable的子类 * 特点: * (1)只能操作String类型 * setProperty(String key,String value) * getProperty(String key) * (2)可以进行远程属性内容的加载(IO支持) * load(InputStream/Reader):加载(读取)属性 * store(OutputStream/Writer,String comment):保存(写出)属性 [comment:属性列表的描述] * */ public class TestProperties { public static void main(String[] args) throws Exception { Properties prop=new Properties(); FileOutputStream fos=new FileOutputStream("d:\\lock.properties"); FileInputStream fis=new FileInputStream("d:\\lock.properties"); //向prop中添加数据 prop.setProperty("bj", "beijing"); prop.setProperty("cd","chengdu"); //将prop中的属性加载到指定目录中 prop.store(fos, "info area"); //从指定目录读取prop的属性 prop.load(fis); System.out.println(prop.getProperty("cd"));//chengdu } }