zoukankan      html  css  js  c++  java
  • java类读取properties文件

    package com.bshinfo.el.userInfo.util;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Properties;

    public class SystemConfigUtil {

        private static SystemConfigUtil systemConfigUtil = null;

        private static Map<String, String> proMap = new HashMap<String, String>();

        private SystemConfigUtil() {

            Properties pro = new Properties();

            try {
                pro.load(new InputStreamReader(SystemConfigUtil.class.getClassLoader().getResourceAsStream("xxx.properties"), "UTF-8"));//根目录下

                Enumeration e = pro.propertyNames();

                while (e.hasMoreElements()) {

                    String key = (String) e.nextElement();

                    String value = (String) pro.get(key);

                    proMap.put(key, value);

                }

            } catch (IOException e) {

                e.printStackTrace();

            }

        }

        public static SystemConfigUtil getInstance() {

            if (systemConfigUtil == null) {

                systemConfigUtil = new SystemConfigUtil();

            }

            return null;

        }

        public static Map<String, String> getProMap() {

            return proMap;

        }

        public static void main(String[] args) {

            // 写一个main方法,来验证一下

            SystemConfigUtil systemConfigUtil = SystemConfigUtil.getInstance();

            SystemConfigUtil systemConfigUtil2 = SystemConfigUtil.getInstance();

            System.out.println(systemConfigUtil == systemConfigUtil2);

            Map m1 = systemConfigUtil.getProMap();

            Map m2 = systemConfigUtil2.getProMap();

            System.out.println(m1 == m2);

            System.out.println(m1.get("test"));
            System.out.println(m1.get("燃油值班员"));
            

        }

    }

  • 相关阅读:
    Vsftp的PASV mode(被动模式传送)和Port模式及 Linux下VsFTP配置全方案
    vsftpd:500 OOPS: vsftpd: refusing to run with writable root inside chroot ()错误的解决方法
    CentOS7.2部署FTP
    Apache与Nginx的优缺点比较
    MySQL存储引擎--MyISAM与InnoDB区别
    CentOS 7下搭建配置SVN服务器
    Remi 安装源
    tmpx75 I2C 温度传感器驱动程序添加
    QT 5.7.0 交叉编译记录
    am335x SGX 移植
  • 原文地址:https://www.cnblogs.com/mybug/p/5430074.html
Copyright © 2011-2022 走看看