<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 閱讀(361) 評論(0)  編輯  收藏 所屬分類: Scala / Java

    主站蜘蛛池模板: 自拍偷自拍亚洲精品情侣| 久久久高清免费视频| mm1313亚洲国产精品美女| 亚洲AV无码AV日韩AV网站| 免费观看的a级毛片的网站| 99999久久久久久亚洲| 日本亚洲免费无线码| 亚洲乱码在线播放| 国产精品久久免费| 亚洲人成图片网站| 国产自产拍精品视频免费看| 黄色三级三级免费看| 久久综合亚洲色HEZYO国产| 国产va免费观看| 久久精品国产精品亚洲艾草网| 久久这里只精品热免费99| 亚洲精品高清国产麻豆专区| 久草免费在线观看视频| 亚洲av永久无码精品秋霞电影秋 | 最近免费中文字幕视频高清在线看| 亚洲avav天堂av在线网爱情| 最近最新的免费中文字幕| 国产精品亚洲一区二区无码| 国产成人精品日本亚洲专区| 久久成人免费大片| 在线观看亚洲AV日韩AV| 全部免费国产潢色一级| 久久青青草原国产精品免费| 亚洲精品福利你懂| 亚洲中文字幕视频国产| 99久久久国产精品免费牛牛| 亚洲精华液一二三产区| 亚洲日产韩国一二三四区| 成人免费在线看片| 成在线人直播免费视频| 久久国产亚洲精品无码| 国产yw855.c免费视频| 99久久精品国产免费| 香蕉视频免费在线| 亚洲激情电影在线| 亚洲人成国产精品无码|