zoukankan      html  css  js  c++  java
  • Properties属性操作

    package com.properties;
    
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.Properties;
    
    /**
     * Properties:Hashtable的子类 
     * 特点:
     * (1)只能操作String类型
     *    setProperty(String key,String value)
     *    getProperty(String key)
     * (2)可以进行远程属性内容的加载(IO支持)
     *   load(InputStream/Reader):加载(读取)属性
     *   store(OutputStream/Writer,String comment):保存(写出)属性 [comment:属性列表的描述]
     *
     */
    public class TestProperties {
         public static void main(String[] args) throws Exception {
            Properties prop=new Properties();
            FileOutputStream fos=new FileOutputStream("d:\lock.properties");
            FileInputStream fis=new FileInputStream("d:\lock.properties");
            //向prop中添加数据
            prop.setProperty("bj", "beijing");
            prop.setProperty("cd","chengdu");
            //将prop中的属性加载到指定目录中
            prop.store(fos, "info area");
            //从指定目录读取prop的属性
            prop.load(fis);
            System.out.println(prop.getProperty("cd"));//chengdu
           
         }
    }
  • 相关阅读:
    软件对标分析
    alpha内测版发布
    第一阶段项目评审
    第一阶段意见汇总
    冲刺(二十)
    冲刺(十九)
    冲刺(十八)
    冲刺(十七)
    冲刺(十六)
    冲刺(十五)
  • 原文地址:https://www.cnblogs.com/yuefeng123/p/7486588.html
Copyright © 2011-2022 走看看