zoukankan      html  css  js  c++  java
  • 读取Properties文件操作

    import java.io.InputStream;
    import java.util.Properties;
    /**
     * 读取system.properties配置文件中的参数
     */
    public class TestProperties {
        private static Properties TestProperties;
        //加载system.properties配置文件,读取文件的配置参数
        private static synchronized void loadProperties() {
            if(null==TestProperties) {
                try {
                    Properties properties=new Properties();
                    InputStream inputStream=TestProperties.class.getClassLoader().getResourceAsStream("system.properties");
                    properties.load(inputStream);
                    TestProperties=properties;
                }catch(Exception e) {
                    throw new RuntimeException("未找到配置文件");
                }
            }
        }
        //读取配置文件中的参数的值
        public void get() {
          loadProperties();
          System.out.println(TestProperties.getProperty("jdbc.driverUrl"));
          System.out.println(TestProperties.getProperty("jdbc.driverClassName"));
          System.out.println(TestProperties.getProperty("jdbc.password"));
          System.out.println(TestProperties.getProperty("jdbc.user"));
        }
        public static void main(String[] args) {
            TestProperties testProperties=new TestProperties();
            testProperties.get();
        }
    }
    jdbc.driverUrl=jdbc:mysql://localhost:3306/idcard?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    jdbc.driverClassName=com.mysql.jdbc.Driver
    jdbc.password=root
    jdbc.user=root
    一纸高中万里风,寒窗读破华堂空。 莫道长安花看尽,由来枝叶几相同?
  • 相关阅读:
    EasyUI
    EasyUI
    EasyUI
    django MTV架构下的网站开发步骤
    Centos7下安装python3
    python 线程间事件通知
    hadoop MapReduce
    hadoop文件配置
    DataFrame 数据去重
    用selenium获取cookies
  • 原文地址:https://www.cnblogs.com/byczyz/p/12209216.html
Copyright © 2011-2022 走看看