Properties的简单使用

来源:互联网 发布:搜狐影音 mac版 编辑:程序博客网 时间:2024/05/16 13:51
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