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);
  • 相关阅读:
    poj 1328 Radar Installation (贪心)
    hdu 2037 今年暑假不AC (贪心)
    poj 2965 The Pilots Brothers' refrigerator (dfs)
    poj 1753 Flip Game (dfs)
    hdu 2838 Cow Sorting (树状数组)
    hdu 1058 Humble Numbers (DP)
    hdu 1069 Monkey and Banana (DP)
    hdu 1087 Super Jumping! Jumping! Jumping! (DP)
    必须知道的.NET FrameWork
    使用记事本+CSC编译程序
  • 原文地址:https://www.cnblogs.com/yimian/p/6558420.html
Copyright © 2011-2022 走看看