zoukankan      html  css  js  c++  java
  • Properties集合_list方法与store方法

    Properties集合和流对象结合的功能

    list()方法:

    import java.util.Properties;
    
    public class PropertiesDemo {
        public static void main(String[] args) {
            propertiesDemo();
        }
    
        public static void propertiesDemo() {
            Properties prop = new Properties();
            prop.setProperty("02", "huangjianfeng");
            prop.setProperty("03", "jianfeng");
            prop.setProperty("04", "feng");
            
            prop.list(System.out);//该方法多用于调式,开发中很少用
        }
    }

    store()方法:

    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    
    public class PropertiesDemo {
        public static void main(String[] args) throws IOException {
            propertiesDemo();
        }
    
        public static void propertiesDemo() throws IOException {
            Properties prop = new Properties();
            prop.setProperty("02", "hujianfeng");
            prop.setProperty("03", "jianfeng");
            prop.setProperty("04", "feng");
            
            //想要将这个集合中的字符串键值信息持久化存储到文件中,需要关联输出流
            FileOutputStream fos = new FileOutputStream("F:\info.txt");
            
            //将集合中的数据存储到文件中,使用store方法
            prop.store(fos, "number+name");//第二个参数表示对这个表的描述,也就是说说明这个表是什么
            fos.close(); 
        }
        
    }
  • 相关阅读:
    懂得拐弯,是人生大智慧!
    人心如落叶
    人生聚散,一切随缘!
    35岁以后你还能干嘛?
    人品好,自带光芒
    有一种心境,叫顺其自然
    304. Range Sum Query 2D
    303. Range Sum Query
    301. Remove Invalid Parentheses
    297. Serialize and Deserialize Binary Tree
  • 原文地址:https://www.cnblogs.com/LO-ME/p/3595478.html
Copyright © 2011-2022 走看看