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);
                }
            }
    
        }
    }
  • 相关阅读:
    非root用户在linux下安装多个版本的CUDA和cuDNN(cuda 8、cuda 10.1 等)
    python相关总结
    可视化滤波器
    Ubuntu 和windows程序区别
    远程服务器运行代码相关
    Ubuntu
    jmeter学习(1)基础支持+安装部署
    python中eval方法的使用
    mysql学习(4)python操作数据库
    mysql学习(3)10045错误,连接不上数据库
  • 原文地址:https://www.cnblogs.com/cfb513142804/p/4279072.html
Copyright © 2011-2022 走看看