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;
    		}
    	}
    }
    





  • 相关阅读:
    FILTER(过滤器)
    HDFS优缺点
    python运算符
    python变量类型
    python变量存储
    python编码问题
    【一:定义】python 简介
    如何学一门新技术
    Django安装
    redis 安装及启动关闭
  • 原文地址:https://www.cnblogs.com/wala-wo/p/5119195.html
Copyright © 2011-2022 走看看