2021.6.13笔记 Properties集合


Properties集合存储数据,遍历数据

在这里插入图片描述
在这里插入图片描述

public class ProPer {
    public static void main(String[] args) {
        method();
    }
    public static void method() {
        Properties pro = new Properties();
        pro.setProperty("小新","6");
        pro.setProperty("妮妮","7");
        pro.setProperty("风间","8");
        Set<String> set = pro.stringPropertyNames();
        for(String key : set) {
            String value = pro.getProperty(key);
            System.out.println(key + "=" + value);
        }
    }
}

原来是命名问题导致报错。


store 方法

在这里插入图片描述

public class ProPer {
    public static void main(String[] args) throws IOException {
        method();
    }
    public static void method() throws IOException {
        Properties pro = new Properties();
        pro.setProperty("小新","6");
        pro.setProperty("妮妮","7");
        pro.setProperty("风间","8");
        FileWriter fw = new FileWriter("H:\\test\\aa.txt");
        pro.store(fw,"store data");     //不可以用中文,会乱码
        fw.close();
    }
}

load 方法

在这里插入图片描述

public class LoadDemo {
    public static void main(String[] args) throws IOException {
        method();
    }
    public static void method() throws IOException {
        Properties pro = new Properties();
        pro.load(new FileReader("H:\\test\\aa.txt"));
        Set<String> strings = pro.stringPropertyNames();
        for (String key : strings) {
            String value = pro.getProperty(key);
            System.out.println(key + "=" + value);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值