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);
                }
            }
    
        }
    }
  • 相关阅读:
    Qt QString转char[]数组
    Qt 如何使窗体初始最大化
    Qt 子窗口监听主窗口信号
    SQL SERVER 日志已满的处理方法 (转)
    C#中的sleep()和wait()
    C#中的sleep()和wait()
    C# 生成1100的随机数
    C# 生成1100的随机数
    gridcontrol 添加行号
    gridcontrol 添加行号
  • 原文地址:https://www.cnblogs.com/cfb513142804/p/4279072.html
Copyright © 2011-2022 走看看