• ClassLoaderTest


    package com.tms.apitest.common;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Properties;
    public class ClassLoaderTest {
    
    	SetLog4j log = new SetLog4j();
    	
    	public String getProperties(String filename, String param) throws IOException {
            // 通过Class 获取资源  
    		
    		String propertiesValue = null;
    //        java.net.URL url = ClassLoaderTest.class.getResource("ClassLoaderTest.class");  
            //log.loggerInfo(url.toString());
            // 通过user.dir获取路径  
            String path = System.getProperty("user.dir");  
      
            Properties prop = new Properties();  
      
            // 通过File方式获取conf.properties  
            String confPath = path.concat(File.separator).concat("src")  
                    .concat(File.separator)
                    .concat("test").concat(File.separator).concat("resources")  
                    .concat(File.separator).concat(filename);  
            //log.loggerInfo(confPath);  
      
            File file = new File(confPath);  
            FileInputStream is = null;  
            if (file.exists() && !file.isDirectory()) {  
                try {  
                    is = new FileInputStream(file);  
                    prop.load(is);  
                    //log.loggerInfo("File Load Successful. " + param + " is: ["  
                    //        + prop.getProperty(param) + "]");  
                    propertiesValue = prop.getProperty(param);
                    prop.clear();  
                } catch (FileNotFoundException e) {  
                    e.printStackTrace();  
                    log.loggerInfo("File not Found Exception.");  
                } catch (Exception e) {  
                    e.printStackTrace();  
                    log.loggerInfo("Properties load Exception.");  
                } finally {  
                    if (is != null) {  
                        try {  
                            is.close();  
                        } catch (IOException e) {  
                            e.printStackTrace();  
                        }  
                    }  
                }  
            } else {  
            	log.loggerInfo("Can not find properties from [" + confPath  
                        + "]");  
            }  
            
    		return propertiesValue;  
    	}
    }
    

      

  • 相关阅读:
    团队作业2
    神琪宝贝
    自我介绍
    新博客破蛋日!
    关于mysql的索引原理与慢查询优化
    mysql主从复制(超简单)
    MySQL 主从复制与读写分离概念及架构分析
    nginx配置image_filter生成缩略图
    关于ueditor多图上传加水印
    linux下php调用root权限实现方案
  • 原文地址:https://www.cnblogs.com/by170628/p/8134619.html
Copyright © 2020-2023  润新知