首页 > 其他 > 详细

分享java读写Properties文件

时间:2014-03-11 20:08:05      阅读:387      评论:0      收藏:0      [点我收藏+]

Properties用来做配置之类的文件存储,比如数据库配置,连接池配置等。

转载请注明出处:分享java读写Properties文件


package com.zuidaima;

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", "zuidaima");
			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();
		}
	}
}

代码下载地址:http://www.zuidaima.com/share/1550463235050496.htm

分享java读写Properties文件,布布扣,bubuko.com

分享java读写Properties文件

原文:http://blog.csdn.net/yaerfeng/article/details/20994891

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!