Java基础-修改Properties配置文件


package com.hspedu.io_;

import org.junit.Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class UpdatePropertiesFile {

    @Test
    public void updatePropertiesFile() throws IOException {
        String filePath = "src\\test.properties";
        Properties properties = new Properties();
        properties.setProperty("user", "root123");
        properties.setProperty("password", "000000");
        properties.store(new FileOutputStream(filePath), "");
    }
}

1、Properties对象的setProperty("key", "value");修改配置文件,如果没有key则新增,如果已经存在key则修改对应的value;

2、store保存方法,第一个参数传入一个输出流OutputStream,第二个参数comments传入字符串注释。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM