Properties的简单使用

package com.JavaSE.day10;

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

public class PropertiesTest {
	public static void main(String[] args) throws FileNotFoundException, IOException {
//		Properties pro = System.getProperties();
//		String version = pro.getProperty("java.version");
//		System.out.println(version);
//		System.out.println(pro.getProperty("java.class.path"));
//		System.out.println(pro.getProperty("os.version"));
//		System.out.println(System.getenv("JAVA_HOME"));
//		System.out.println(System.currentTimeMillis());
//		Date date = new Date(System.currentTimeMillis());
//		SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		System.out.println(simpleFormat.format(date));
		
//		System.out.println("-----------------------");
		
		Properties pro1 = new Properties();
//		File file1 = new File("freshbin/freshbinIP.property");
//		pro1.load(new FileInputStream(file1));
//		
//		String ip = pro1.getProperty("ip");
//		System.out.println(ip);
//		
//		String port = pro1.getProperty("port");
//		System.out.println(port);
//		
//		System.out.println("---------------------");
		
		pro1.load(new FileInputStream("freshbin/test.property"));
		System.out.println(pro1.getProperty("hello"));
		
		System.out.println("----------------------");
		
		//修改hello键的值
		pro1.setProperty("hello", "freshbin");
		
		System.out.println(pro1.getProperty("hello"));
		
		System.out.println("-----------------------");
		
		OutputStream os = new FileOutputStream("freshbin/test.property");
		
		//增加一个键值对
		pro1.setProperty("h1", "h2");
		pro1.store(os, "");//如果注释掉,那么配置文件的内容都写不进去
		
		System.out.println(pro1.getProperty("h1"));
		os.flush();
		os.close();
		
	}
}


以上是Properties的简单使用,其实也就是get,set,load,store与输入输出流的使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值