package com.XXX.park.common.utils;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class UpLocationMarker {
private static Properties props = new Properties();
static {
try {
props.load(new InputStreamReader(UpLocationMarker.class.getClassLoader().getResourceAsStream("upLocationMarker.properties"), "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String strs = sw.toString();
log.error(strs);
}
}
public static String getFlag(String flagName) {
return props.getProperty(flagName);
}
public static void setFlag(String flagName, String flag) {
props.setProperty(flagName, flag);
flush();
}
public static String getLastTimeOfWhitelist() {
return props.getProperty("lastTimeOfWhitelist");
}
public static void setLastTimeOfWhitelist(String lastTimeOfWhitelist) {
props.setProperty("lastTimeOfWhitelist", lastTimeOfWhitelist);
flush();
}
public static String getLastTimeOfYJS() {
return props.getProperty("lastTimeOfYJS");
}
public static void setLastTimeOfYJS(String lastTimeOfYJS) {
props.setProperty("lastTimeOfYJS", lastTimeOfYJS);
flush();
}
public static String getLastTimeOfJG() {
return props.getProperty("lastTimeOfJG");
}
public static void setLastTimeOfJG(String lastTimeOfJG) {
props.setProperty("lastTimeOfJG", lastTimeOfJG);
flush();
}
public static String getLastTimeOfXS() {
return props.getProperty("lastTimeOfXS");
}
public static void setLastTimeOfXS(String lastTimeOfXS) {
props.setProperty("lastTimeOfXS", lastTimeOfXS);
flush();
}
private static void flush() {
String path = "";
try {
path = UpLocationMarker.class.getClassLoader().getResource("upLocationMarker.properties").toURI().getPath();
FileOutputStream outputFileClass = new FileOutputStream(path.replaceAll("%20", " "));
// FileOutputStream outputFileJava = new FileOutputStream(
// "F:/my_eclipse_work_space/IDTECH-WS-MID/src/main/resources/upLocationMarker.properties");
props.store(outputFileClass, null);
// props.store(outputFileJava, null);
// outputFileJava.flush();
// outputFileJava.close();
outputFileClass.flush();
outputFileClass.close();
} catch (FileNotFoundException e) {
log.error("文件路径格式错误: {}", e.getMessage() + path);
} catch (Exception e) {
log.error("更新文件异常", e.getMessage());
}
}
}
配置文件读写
最新推荐文章于 2021-05-25 10:16:24 发布