zoukankan      html  css  js  c++  java
  • Properties配置文件练习

    package IO.file.test;
    
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.ObjectInputStream;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.io.Writer;
    import java.util.Properties;
    import java.util.Set;
    
    public class PropertiesDemo {
        public static void main(String[] args) throws IOException {
            method_4();
    
        }
        private static void method_4() throws IOException {
            Properties pro = new Properties();
            BufferedReader bufr=new BufferedReader(new FileReader("a.txt"));
            String line=null;
            while((line=bufr.readLine())!=null)
            {
                    if(line.startsWith("#"))
                                continue;
                String[] arr=line.split("=");
        //        System.out.println(arr[0]+" "+arr[1]);
                pro.setProperty(arr[0], arr[1]);
            }
            pro.list(System.out);
            bufr.close();
        }
        public static void method_3() throws IOException {
        Properties pro = new Properties();
        FileInputStream fis=new FileInputStream("a.txt");
        pro.load(fis);
        pro.list(System.out);
        }
         static void method_2() throws IOException
        {
            Properties pro = new Properties();
            pro.setProperty("zhangsan", "30");
            pro.setProperty("lisi", "32");
            pro.setProperty("maer", "34");
            pro.setProperty("mazi", "45");
            pro.setProperty("wangwu", "12");
            pro.store(new FileWriter("a.txt"), "name+age");
            //pro.store(new FileOutputStream("a.txt"), "name+age");
        }
        public static void method_1()
        {
            Properties pro = new Properties();
            pro.setProperty("zhangsan", "30");
            pro.setProperty("lisi", "32");
            pro.setProperty("maer", "34");
            pro.setProperty("mazi", "45");
            pro.setProperty("wangwu", "12");
            pro.list(System.out);
            System.out.println();
            pro = System.getProperties();
            System.out.println(pro);
            // 修改值
            /*
             * pro.setProperty("mazi", "22"); Set<String>
             * names=pro.stringPropertyNames(); for(String name:names){ String
             * value=pro.getProperty(name); System.out.println(name); }
             */
        }
    
    
    }
  • 相关阅读:
    Hadoop 2.7.1 源代码目录结构分析
    Jit
    java性能分析工具
    最近一个dish项目的建设思考
    mysql的ACID的理解
    实践中积累沟通组织经验
    系统性能--磁盘/网卡
    系统性能--CPU
    调停者模式的批斗
    channel和Stream的对比
  • 原文地址:https://www.cnblogs.com/kedoudejingshen/p/2731778.html
Copyright © 2011-2022 走看看