zoukankan      html  css  js  c++  java
  • Properties类读取配置文件

    package com.wzy.t4;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    
    
    public class PropertityTest {
        public static void main(String[] args) {
            
            Properties file = new Properties();
            file.setProperty("name", "小明");
            file.setProperty("passwd", "123456");
            file.setProperty("driver", "com.mysql.jdbc.Driver");
            file.setProperty("host", "127.0.0.1");
    //        System.out.println(file.getProperty("name", "defaultValue"));
    //        System.out.println(file.getProperty("name1", "defaultValue"));
            
            try {
                //将数据保存到本地磁盘,后缀一般为(.properties)以表明是Properties使用的
                file.store(new FileOutputStream(new File("d:"+File.separator+"profile.properties")), "注释内容");
                //从本地磁盘读取文件或从类路径下读取数据
                file.load(new FileInputStream(new File("d:"+File.separator+"profile.properties")));
                System.out.println(file.getProperty("host", ""));
                
                /**
                    #u6CE8u91CAu5185u5BB9
                    #Wed Jun 01 14:16:14 CST 2016
                    passwd=123456
                    name=u5C0Fu660E
                    host=127.0.0.1
                    driver=com.mysql.jdbc.Driver
                 * */
                
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            
            
        }
    }
  • 相关阅读:
    git diff的使用
    composer安装特别慢的解决方案
    laravel5.5 excel的安装和使用
    laravel中有条件使用where
    数据结构10——强连通
    数据结构9——桥
    数据结构8——割点
    数据结构7——费用流
    数据结构6——网络流
    数据结构5——二分图匹配
  • 原文地址:https://www.cnblogs.com/wwzyy/p/5549483.html
Copyright © 2011-2022 走看看