zoukankan      html  css  js  c++  java
  • 读取.properties配置文件并保存到另一个.properties文件内

    代码如下

    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream; 
    import java.util.Iterator;
    import java.util.Properties; 
    
    public class PropertyTest {
        public static void main(String[] args) { 
            Properties prop = new Properties();     
            try{
                //读取属性文件a.properties
                InputStream in = new BufferedInputStream (new FileInputStream("a.properties"));
                prop.load(in);     ///加载属性列表
                Iterator<String> it=prop.stringPropertyNames().iterator();
                while(it.hasNext()){
                    String key=it.next();
                    System.out.println(key+":"+prop.getProperty(key));
                }
                in.close();
                
                ///保存属性到b.properties文件
                FileOutputStream oFile = new FileOutputStream("b.properties", true);//true表示追加打开
                prop.setProperty("phone", "10086");
                prop.store(oFile, "The New properties file");
                oFile.close();
            }
            catch(Exception e){
                System.out.println(e);
            }
        } 
    }

    转自:https://www.cnblogs.com/xudong-bupt/p/3758136.html

  • 相关阅读:
    CodeForces-1263D Secret Passwords 并查集 求连通分量
    Virtual Friends HDU
    AreYouBusy HDU
    Jack Straws POJ
    Divisibility by 25 CodeForces
    逃离迷宫 HDU
    Find a way HDU
    Stall Reservations POJ
    Three displays CodeForces
    Radar Installation POJ
  • 原文地址:https://www.cnblogs.com/cailijuan/p/9047318.html
Copyright © 2011-2022 走看看