java.lang.Object
继承者 java.util.Dictionary<K,V>
继承者 java.util.Hashtable<Object,Object>
继承者 java.util.Properties
所有已实现的接口:
Serializable, Cloneable, Map<Object,Object>

1.构造方法
Properties();
Properties(Properties default):创建一个带有默认值的空属性列表
2.主要方法:
getProperty(String key)通过指定的键获取属性,返回的是一个字符串
load(InputStream inStream)从输入流中读取属性列表
load(Reader reader)按简单的面向行的格式从输入字符流中读取属性列表
setProperty(String key,String value),向列表中输入键值对
store(OutputStream os,String commit)将此 Properties 表中的属性列表(键和元素对)写入输出流,commit为注释
store(Writer writer,String commit)将此 Properties 表中的属性列表(键和元素对)写入输出字符
stringPropertyNames();返回一个set集合的键值对字符串

public class Demo09 {
    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.setProperty("zsh", "1");
        properties.setProperty("zms","2");
        properties.setProperty("sks","3");
        Set<String> strings = properties.stringPropertyNames();
        for(String key:strings){
            String value = properties.getProperty(key);
            System.out.println(key+"="+value);
        }
    }
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class Demo10 {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        properties.setProperty("sks","180");
        properties.setProperty("zsh","170");
        FileWriter fileWriter = new FileWriter("G:" + File.separator + "demo.txt");
        properties.store(fileWriter,"sava data");
        fileWriter.close();
    }
}
posted on 2020-07-22 20:56  凸凸大军的一员  阅读(37)  评论(0编辑  收藏  举报