首页>代码>分享java读写Properties文件>/properties/src/com/javaniu/Main.java
package com.javaniu;

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

public class Main {

	public static void main(String[] args) {
		Properties property = new Properties();
		try {
			File file = new File("c:/db.properties");
			if (!file.exists()) {
				file.createNewFile();
			}
			// 写入
			property.setProperty("database", "localhost");
			property.setProperty("user", "javaniu");
			property.setProperty("password", "password");
			property.store(new FileOutputStream(file), null);

			property.load(new FileInputStream(file));

			// 读取
			System.out.println(property.getProperty("database"));
			System.out.println(property.getProperty("user"));
			System.out.println(property.getProperty("password"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
最近下载更多
wangdongkui  LV1 2020年3月28日
jaonsang  LV25 2019年11月4日
Yang哈哈  LV6 2019年6月26日
谭鬼鬼  LV48 2018年6月29日
故事_sun  LV26 2018年5月16日
梦醒繁华丶  LV19 2017年8月3日
wyx065747  LV67 2017年6月28日
caixiajames  LV9 2016年10月20日
jinkuake  LV2 2016年6月21日
billravi  LV1 2016年4月11日
最近浏览更多
heqian  LV16 2023年1月10日
gan857569302  LV9 2020年6月24日
kevin72 2020年5月11日
暂无贡献等级
Rommel  LV27 2020年4月18日
hzhsh0223  LV18 2020年4月17日
wangdongkui  LV1 2020年3月28日
bjgaocl  LV13 2020年3月21日
jaonsang  LV25 2019年11月4日
liangliang2049  LV2 2019年10月14日
lion1984  LV2 2019年8月13日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友