<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Chan Chen Coding...

    Java Properties file examples

    In Java, properties file is always used to store the configuration data or settings. In this example we will show you how to read and write to/from a properties file.

    1. Example 1

    In this example, set the property value and write it into a properties file named “config.properties“. The new saved properties file will be stored at your project root folder.

    package com.mkyong.common;   
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;  
    public class App {
        public static void main( String[] args )
        {
            Properties prop = new Properties();
      try {
    //set the properties value
    prop.setProperty("database", "localhost");
    prop.setProperty("dbuser", "mkyong");
    prop.setProperty("dbpassword", "password");
      //save properties to project root folder
    prop.store(new FileOutputStream("config.properties"), null);
      } catch (IOException ex) {
    ex.printStackTrace();
    }
    }
    }

    Output – The content of the file “config.properties

    #Mon Jan 11 18:54:40 MYT 2010 
    dbpassword=password
    database=localhost
    dbuser=mkyong

    2. Example 2

    In this 2nd example, load a properties file named “config.properties” and retrieved the saved property value.

    package com.mkyong.common;   
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.Properties;
      public class App {
    public static void main( String[] args )
    {
    Properties prop = new Properties();
      try {
    //load a properties file
    prop.load(new FileInputStream("config.properties"));
      //get the property value and print it out
    System.out.println(prop.getProperty("database"));
    System.out.println(prop.getProperty("dbuser"));
    System.out.println(prop.getProperty("dbpassword"));
      } catch (IOException ex) {
    ex.printStackTrace();
    }
      }
    }

    Output

    localhost
    mkyong
    password


    -----------------------------------------------------
    Silence, the way to avoid many problems;
    Smile, the way to solve many problems;

    posted on 2012-06-07 13:05 Chan Chen 閱讀(365) 評論(0)  編輯  收藏 所屬分類: Scala / Java

    主站蜘蛛池模板: 亚洲五月综合缴情在线观看| 国产精品1024永久免费视频| 国产人成免费视频| 亚洲精品精华液一区二区| 久久国产精品免费一区二区三区| 99久久国产亚洲综合精品| 国产在线观看片a免费观看| 亚洲精品视频免费| 亚洲国产成人片在线观看无码| 亚洲福利一区二区| 希望影院高清免费观看视频| 亚洲a级成人片在线观看| 久久WWW免费人成人片| 天堂亚洲国产中文在线| 日韩中文字幕在线免费观看| 精品免费AV一区二区三区| 免费一级国产生活片| 一级特黄录像视频免费| 亚洲国产精品无码久久一线| 7x7x7x免费在线观看| 亚洲国产日韩视频观看| 国产特级淫片免费看| 久久精品免费网站网| 久久丫精品国产亚洲av不卡 | 亚洲一区二区三区在线网站| 久久精品女人天堂AV免费观看| 亚洲精品美女久久7777777| 亚洲福利精品电影在线观看| 青青操在线免费观看| 亚洲人成影院午夜网站| 免费一级大黄特色大片| 四虎国产成人永久精品免费| 97久久国产亚洲精品超碰热| 亚洲av中文无码| 99久9在线|免费| 精品国产亚洲AV麻豆| 亚洲国产二区三区久久| 国产成人涩涩涩视频在线观看免费| 91成人免费福利网站在线| 亚洲制服丝袜第一页| 亚洲国产天堂在线观看|