java 正则表达式和properties文件修改基本使用

正则表达式基础使用,此处是用来判断时间格式(123020)

String regex = "{2}[012]\\d[0-6]\\d[0-6]\\d";

Pattern pattern = Pattern.compile(regex);

pattern.matcher(startTime).matches();

读取配置文件,更改配置项后写入

String path = System.getProperty("smm.SMMPayCenter") + "/WEB-INF/classes/tradeTime.properties";

Properties properties = new Properties();

logger.info("更改前,startTime : " + properties.getProperty("startTime")
        +", closeTime : " + properties.getProperty("closeTime"));

FileInputStream fis = new FileInputStream(path); 

properties.load(fis);

properties.setProperty("startTime", startTime);

properties.setProperty("endTime", endTime);

logger.info("更改后,startTime : " + properties.getProperty("startTime")
+", closeTime : " + properties.getProperty("closeTime"));

fis.close();

FileOutputStream fos = new FileOutputStream(path);

properties.store(fos, "id:" +account.getId()+",account:"+account.getAccount());

fos.close();

你可能感兴趣的:(代码累积)