zoukankan      html  css  js  c++  java
  • java IO流 七、Properties

    Properties的概述和作为Map集合的使用
    * A:Properties的概述
    * Properties 类表示了一个持久的属性集。
    * Properties 可保存在流中或从流中加载。
    * 属性列表中每个键及其对应值都是一个字符串。
    * B:案例演示
    * Properties作为Map集合的使用

    ###Properties的特殊功能使用

    * A:Properties的特殊功能
    * public Object setProperty(String key,String value)
    * public String getProperty(String key)
    * public Enumeration<String> stringPropertyNames()
    * B:案例演示
    * Properties的特殊功能

    使用父类继承方法  :put()

        public static void demo1() {
            Properties prop = new Properties();
            prop.put("abc", 123);
            System.out.println(prop);
        }

    properties特有方法:

        public static void demo2() {
            Properties prop = new Properties();
            prop.setProperty("name", "张三");
            prop.setProperty("tel", "18912345678");
            
            //System.out.println(prop);
            Enumeration<String> en = (Enumeration<String>) prop.propertyNames();
            while(en.hasMoreElements()) {
                String key = en.nextElement();                //获取Properties中的每一个键
                String value = prop.getProperty(key);        //根据键获取值
                System.out.println(key + "="+ value);
            }

    ###Properties的load()和store()功能


    * A:Properties的load()和store()功能
    * B:案例演示
    * Properties的load()和store()功能

            Properties prop = new Properties();
            prop.load(new FileInputStream("config.properties"));        //将文件上的键值对读取到集合中
            prop.setProperty("tel", "18912345678");
            prop.store(new FileOutputStream("config.properties"), null);//第二个参数是对列表参数的描述,可以给值,也可以给null
            System.out.println(prop);
  • 相关阅读:
    手打AC的第2道数位DP:BZOJ1799: [Ahoi2009]self 同类分布
    Oracle PL/SQL编程基础
    Oracle高级查询,事物,过程及函数
    缓存技术
    图形化报表
    网站配置与部署
    Oracle 空间管理
    Oracle 10g体系结构及安全管理
    ORACLE 数据库概述
    jQuery中的Ajax应用
  • 原文地址:https://www.cnblogs.com/yimian/p/6558420.html
Copyright © 2011-2022 走看看