<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

    主站蜘蛛池模板: 国产精品亚洲玖玖玖在线观看 | 亚洲av午夜福利精品一区| 亚洲欧美日韩中文无线码| 久视频精品免费观看99| 亚洲国产精品国自产电影| 国产午夜无码精品免费看 | 18级成人毛片免费观看| 亚洲精品免费观看| 久久99国产乱子伦精品免费| 亚洲视频精品在线| 四虎精品视频在线永久免费观看| 亚洲电影唐人社一区二区| 午夜爱爱免费视频| 亚洲熟妇AV一区二区三区宅男| 毛片视频免费观看| 久久精品国产亚洲AV未满十八| 又色又污又黄无遮挡的免费视| 免费福利资源站在线视频| 亚洲午夜精品第一区二区8050| 成人免费乱码大片A毛片| 亚洲V无码一区二区三区四区观看 亚洲αv久久久噜噜噜噜噜 | 999久久久免费精品国产| 亚洲精品天堂在线观看| 国产做床爱无遮挡免费视频| 成人免费视频一区二区| 亚洲精品午夜国产VA久久成人 | 成人免费毛片内射美女-百度| 亚洲砖码砖专无区2023| 国产人妖ts在线观看免费视频| 成年女人A毛片免费视频| 亚洲综合无码一区二区| 在线免费观看一级毛片| www免费插插视频| 亚洲经典在线中文字幕| 国产高清在线精品免费软件 | 亚洲视频中文字幕在线| 午夜男人一级毛片免费| a级毛片视频免费观看| 亚洲三级在线播放| 十八禁无码免费网站| 亚洲国产精品免费观看|