springboot 读写properties文件

springboot 读写properties文件

public static void writeProperties(String key, String value) {
    try {
        String path = getRootPath() + "/sync_mongo_40/";
        File pathFile = new File(path);
        if (!pathFile.exists()) {
            pathFile.mkdirs();
        }
        File updateFile = new File(path + FILE_NAME);
        if (!updateFile.exists()) {
            updateFile.createNewFile();
        }
        Properties properties = new Properties(); 
        properties.load(new FileInputStream(updateFile));    //从流读取properties文件内容
        properties.setProperty(key, value);   //写入内容
        properties.store(new FileOutputStream(updateFile), "UTF-8");   //保存到流
        log.info("writer file:[" + FILE_NAME + "] success-------key:" + key + " | value:" + value);
    } catch (Exception e) {
        e.printStackTrace();
        log.error("create [" + FILE_NAME + "] faild!");
    }
}

 

你可能感兴趣的:(properties,springboot,springboot,properties文件)