public class InitSystem {
public static Properties PROPS = new Properties();
static {
try {
load();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static void load() throws IOException {
InputStream input = null;
try {
input = Thread.currentThread().getContextClassLoader().getResourceAsStream("config/system.properties");
PROPS.load(new InputStreamReader(input, "UTF-8"));
} finally {
IOUtils.closeQuietly(input);
}
}
public static String getString(String key) {
return PROPS.getProperty(key);
}
public static String getRequiredString(String key) {
String value = getString(key);
if (value == null) {
throw new RuntimeException("can't find value by key[" + key + "]");
}
return value;
}
}
java读取properties配置文件,并解决中文乱码
最新推荐文章于 2023-07-04 16:23:18 发布