Java>Properties,setProperty(),stringPropertyNames(),store(),load()

Properties
// 使用方法 use method
setProperty(String str_key,String str_value)

// 返回值是一个Set集合
stringPropertyNames():return value is Set Collection

// 将数据存储到硬盘上
store(FileWriter fwobj,String comments)

// 将硬盘上的数据读取到内存中
load(FileReader fr)

public class PropertyDome {
    public static void main(String[] args) throws IOException {
        // new PropertyDome().method_01();
        new PropertyDome().method_02();
    }
    public void method_01() throws IOException {
        Properties pro01 = new Properties();
        pro01.setProperty("yuanhao01","18");
        pro01.setProperty("yuanhao02","18");
        pro01.setProperty("yuanhao03","18");
        pro01.setProperty("yuanhao04","18");
        pro01.setProperty("yuanhao05","18");

        Set<String> key_string = pro01.stringPropertyNames();
        // iterator ergodic
        Iterator<String> iterator_pro = key_string.iterator();
        while (iterator_pro.hasNext()){
            String key = iterator_pro.next();
            System.out.println("Key is : " + key + "\tValue is : " + pro01.getProperty(key));
        }
        // for ergodic
        for (String key : key_string){
            System.out.println("Key is : " + key + "\tValue is : " + pro01.getProperty(key));
        }
        // store method
        FileWriter fileWriter01 = new FileWriter("E:\\folder_io_dome\\a_01.prop");
        pro01.store(fileWriter01,"This is property object!! 01");
        fileWriter01.close();
    }
    public void method_02() throws IOException{
        Properties pro01 = new Properties();
        FileReader fileReader01 = new FileReader("E:\\folder_io_dome\\a_01.prop");
        pro01.load(fileReader01);

        Set<String> key_string = pro01.stringPropertyNames();
        // for ergodic
        for (String key : key_string){
            System.out.println("Key is : " + key + "\tValue is : " + pro01.getProperty(key));
        }
        fileReader01.close();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值