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);
                }
            }
    
        }
    }
  • 相关阅读:
    点分治 / 点分树题目集
    HNOI2019 游记
    WC2019 题目集
    SA / SAM 题目集
    Min_25 筛小结
    NOIP2018 差点退役记
    Atcoder 乱做
    DP及其优化
    计数与概率期望小结
    分库分表之后全局id咋生成?
  • 原文地址:https://www.cnblogs.com/cfb513142804/p/4279072.html
Copyright © 2011-2022 走看看