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

    读取配置文件

    package com.seecen.test;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Enumeration;
    import java.util.Iterator;
    import java.util.Properties;
    import java.util.Map.Entry;
    
    public class ReaderProperties {
    
        public static void main(String[] args) {
            Properties properties = new ReaderProperties().loadProperties("/jdbc.properties");
            Enumeration<?> enu = properties.propertyNames();  
            while (enu.hasMoreElements()) {  
                Object key = enu.nextElement();  
                System.out.println(key);  
            }  
            Enumeration<Object> enu2 = properties.elements();  
            while (enu2.hasMoreElements()) {  
                Object value = enu2.nextElement();  
                System.out.println(value);  
            }
            
            Iterator<Entry<Object, Object>> it = properties.entrySet().iterator();  
            while (it.hasNext()) {  
                Entry<Object, Object> entry = it.next();  
                Object key = entry.getKey();  
                Object value = entry.getValue();  
                System.out.println("key   :" + key);  
                System.out.println("value :" + value);  
                System.out.println("---------------");  
            }  
        }
    
        
        public Properties loadProperties(String resources) {
            // 使用InputStream得到一个资源文件
            InputStream inputstream = this.getClass()
            .getResourceAsStream(resources);
            // new 一个Properties
            Properties properties = new Properties();
            try {
                // 加载配置文件
                properties.load(inputstream);
                return properties;
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    inputstream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
    
        }
    }
  • 相关阅读:
    Web安全测试
    性能测试---并发用户计算
    浅谈软件性能测试中关键指标的监控与分析
    fiddler抓包——IOS
    Linux下查看CPU型号,内存大小,硬盘空间,进程等的命令(详解)
    windows 升级pip
    java 使用Iterator 迭代器遍历AList、Set、Map
    springboot 封装redis工具类
    idea 取消@Autowired 不建议字段注入的警告
    查看服务器相关
  • 原文地址:https://www.cnblogs.com/cfb513142804/p/4279072.html
Copyright © 2011-2022 走看看