java 常用工具整理

时间:2022-03-05 20:31:13

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