<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

    主站蜘蛛池模板: 91久久亚洲国产成人精品性色| 日韩一级在线播放免费观看| 亚洲中文字幕在线第六区| 国产一区二区三区亚洲综合 | 国产精品免费一区二区三区四区| 成人亚洲性情网站WWW在线观看| 免费观看又污又黄在线观看| 又大又黄又粗又爽的免费视频| 国产亚洲精品美女| www.亚洲精品| 中文字幕免费人成乱码中国| 在线日韩日本国产亚洲| 特级做A爰片毛片免费看无码| 亚洲日韩精品一区二区三区无码| 国产成人免费AV在线播放 | 亚洲国产精品无码第一区二区三区 | 亚洲精品国产成人| 国产片AV片永久免费观看| 国产精品亚洲片在线va| 免费看AV毛片一区二区三区| 羞羞网站在线免费观看| 亚洲中文字幕无码不卡电影| 无码国产精品一区二区免费式芒果 | 亚洲久热无码av中文字幕| 免费国产成人高清在线观看麻豆| 无套内谢孕妇毛片免费看看| 国产亚洲自拍一区| 2020因为爱你带字幕免费观看全集 | 国产亚洲中文日本不卡二区| 国产免费人人看大香伊| 青青操免费在线视频| 亚洲手机中文字幕| 国产免费一区二区三区VR| 99精品视频免费| ass亚洲**毛茸茸pics| 免费萌白酱国产一区二区| 91视频精品全国免费观看| 亚洲av乱码一区二区三区| 亚洲午夜无码AV毛片久久| 99xxoo视频在线永久免费观看| 亚洲1区2区3区精华液|