zoukankan      html  css  js  c++  java
  • 读取properties文件

         假设项目名称为myproject

    public class UtilConfig {
    	
    	private static final Properties prop;
    	
    	static {
    		prop = new Properties();
    		try {
    			String PROPERTIES_FILE_SYSTEM_VAR = "moral.website.properties";
    			String propertiesFile = System.getProperty(PROPERTIES_FILE_SYSTEM_VAR);
    			if ( propertiesFile == null ) {
    				propertiesFile = "/setup/myproject.properties";
    			}
    			prop.load(UtilConfig.class.getResourceAsStream(propertiesFile));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static int getInt(String key) {
    		return getInt(key, 100);
    	}
    	
    	public static int getInt(String key, int defaultValue) {
    		try {
    			return  Integer.parseInt(prop.getProperty(key, String.valueOf(defaultValue)));
    		} catch (Exception e) {
    			return defaultValue;
    		}
    	}
    	
    	public static String getString(String key, String defaultValue) {
    		return prop.getProperty(key, defaultValue);
    	}
    	
    	public static String getString(String key) {
    		return prop.getProperty(key);
    	}
    	
    	public static long getLong(String key) {
    		return getLong(key, 1000L);
    	}
    	
    	public static long getLong(String key, long defaultValue) {
    		try {
    			return  Long.parseLong(prop.getProperty(key, String.valueOf(defaultValue)));
    		} catch (Exception e) {
    			return defaultValue;
    		}
    	}
    }
    





  • 相关阅读:
    django之项目建立
    云监控服务比较
    2014 中华架构师大会 回顾
    计算字符串相似度算法——Levenshtein
    Maximum Likelihood 最大似然估计
    Laplacian eigenmap 拉普拉斯特征映射
    SparseLDA算法
    eigenvalues problem
    kernel function
    半监督学习[转]
  • 原文地址:https://www.cnblogs.com/wala-wo/p/5119195.html
Copyright © 2011-2022 走看看