JAVA中 Properties结合io字符流存取

package Iodemo;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

public class PropertiesDemo {
    public static void main(String[] args) throws IOException {
     writes();
     reads();
    }

    private static void reads() throws IOException {
        FileReader fileReader = new FileReader("1.txt");
        Properties pp = new Properties();
        pp.load(fileReader);
        fileReader.close();
        System.out.println(pp);

    }

    private static void writes() throws IOException {
        Properties pp = new Properties();
        pp.setProperty("aaa","111");
        pp.setProperty("bbb","222");
        FileWriter f = new FileWriter("1.txt");
        pp.store(f,null);
        f.close();
    }
}

 

posted @ 2022-04-05 18:23  phpwyl  阅读(18)  评论(0编辑  收藏  举报