java 常用工具整理

mapUtil map操作工具类

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.2</version>
        </dependency>

获取配置文件工具类

public class PropertiesUtil {

	private static final String PATH = "conf.properties";

    public static String getValue(String key){
        Properties pps = new Properties();
        InputStream in = null;
        try {
//            in = new BufferedInputStream (new FileInputStream(PATH));
            in = Thread.currentThread().getContextClassLoader().getResourceAsStream(PATH);
            pps.load(in);
            String value = pps.getProperty(key);
            return value;
        }catch (IOException e) {
            e.printStackTrace();
            return null;
        }finally {
        	try{
        		if(in != null){
			        in.close();
		        }
        	}catch (IOException e) {
        		e.printStackTrace();
			}
		}
    }

    public static Integer getIntValue(String key){
	    String value = getValue(key);
	    return Integer.parseInt(value);
    }

}

posted on 2019-01-10 15:33  朱春旺  阅读(112)  评论(0编辑  收藏  举报