zoukankan      html  css  js  c++  java
  • 读取Config文件工具类 PropertiesConfig.java

    1. package com.util;  
    2.   
    3. import java.io.BufferedInputStream;  
    4. import java.io.FileInputStream;  
    5. import java.io.InputStream;  
    6. import java.util.Properties;  
    7. /** 
    8.  * 读取Config文件工具类 
    9.  * @version 1.0 
    10.  * @since JDK 1.6 
    11.  */  
    12. public class PropertiesConfig {    
    13.         
    14.     /**  
    15.      * 获取整个配置文件中的属性 
    16.      * @param filePath 文件路径,即文件所在包的路径,例如:java/util/config.properties  
    17.      */    
    18.     public static Properties readData(String filePath) {    
    19.         filePath = getRealPath(filePath);  
    20.         Properties props = new Properties();    
    21.         try {    
    22.             InputStream in = new BufferedInputStream(new FileInputStream(filePath));    
    23.             props.load(in);    
    24.             in.close();    
    25.             return props;    
    26.         } catch (Exception e) {    
    27.             e.printStackTrace();    
    28.             return null;    
    29.         }    
    30.     }    
    31.       
    32.     private static String getRealPath(String filePath) {  
    33.         //获取绝对路径 并截掉路径的”file:/“前缀    
    34.         return PropertiesConfig.class.getResource("/" + filePath).toString().substring(6);  
    35.     }  
  • 相关阅读:
    实验吧之snake
    实验吧之Canon
    实验吧之紧急报文
    实验吧之deeeeeeaaaaaadbeeeeeeeeeef-200
    Centos Linux 使用Yum安装Go和配置环境
    harbor仓库搭建
    教你怎么半天搞定Docker
    教你分分钟搞定Docker私有仓库Registry
    kubernetes学习:CKA考试题
    Python基础知识
  • 原文地址:https://www.cnblogs.com/swite/p/5168731.html
Copyright © 2011-2022 走看看