properties向文件中添加数据

package com.day16.test1;

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

public class Test {
	public static void main(String[] args) {
		// 创建属性列表对象
		Properties properties = new Properties();
		// 添加映射关系
		properties.setProperty("g001", "何明雨");
		properties.setProperty("g002", "王正宇");
		properties.setProperty("g003", "桂先松");

		try {
			// 创建输出流对象
			FileWriter fWriter = new FileWriter("e.txt");
			properties.store(fWriter, "欧巴夹");

			// 释放资源
			fWriter.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42591732/article/details/94717783