Properties文件读取工具类
程序员文章站
2022-05-10 08:45:17
...
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class BasePropertiesUtils
{
private static Properties properties = null;
private synchronized static void init()
{
properties = new Properties();
try(InputStream input = ClassLoader.getSystemResourceAsStream("application.properties"))
{
properties.load(input);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public static String getValue(String key){
if(properties==null){
init();
}
return properties.getProperty(key).trim();
}
public static Integer getIntValue(String key)
{
return Integer.valueOf(getValue(key));
}
}
下一篇: Python 获取当前文件所在目录