package utils;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang3.StringUtils;/**
• liqi
• 20190530
*/
public class PropertyConfigUtil {
public static void main(String[] args) {
try {
//E:\..\target\classes
//E:\..\target\
//E:\..\WEB-INF\classes
//获取配置文件路径
String path = PropertyConfigUtil.class.getClassLoader().getResource("config.properties").getPath();
//方法一:
//添加maven 配置
commons-configuration
commons-configuration
1.10
//代码
path= StringUtils.substringBefore(path, “字符串”);
PropertiesConfiguration config = new PropertiesConfiguration(path);
//添加或修改项
config.setProperty(“update_databese”, “false”);
config.save();//方法二:
// Properties prop = new Properties();
// //读取配置文件
// FileInputStream in = new FileInputStream(path);
// //加载
// prop.load(in);
// //获取
// prop.getProperty(“update_databese”);
// //设置
// prop.setProperty(“update_databese”, “false”);
// in.close();
// //写到配置文件
//ture 开启追加
//false 重置内容,注意:无序写入
// FileOutputStream outputStream = new FileOutputStream(path,true);
//追加项
// prop.store(outputStream, “IS_Update_DB”);
// outputStream.close();
} catch (Exception e) {
System.out.println(e);
}
}
}