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

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

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

    yxhxj2006

    常用鏈接

    統計

    最新評論

    JAVA讀取Properties配置文件


    JAVA獲取文件絕對路徑Thread.currentThread().getContextClassLoader().getResource("abc.properties");                                   


     配置文件:XXX.properties 常用操作


     1:加載properties配置文件
      /**
         * 根據key從Properties對象中得到相應的值
         * 
    @param key
         * 
    @return 對應的值
         
    */
        public static String getValue(String key) {
            if (p !=  null) {
                return p.getProperty(key);
            }
            String property = null
            InputStream in = null;
            
            try {
                System.out.println("gleepay.properties is path : " + gleepayURL.getFile());
                File file = new File(gleepayURL.getFile());
                in = new FileInputStream(file);
                p = new Properties();
                p.load(in);
                property = p.getProperty(key);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }  finally {
                if (in != null) {
                    try {
                            in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return property;
        }

    2:寫入propertis配置信息
    /**
         * 寫入properties信息
         * 
    @param parameterKey
         * 
    @param parameterValue
         * 
         * 
    @return
         
    */
        public static void writeProperties_MACkey(String parameterKey, String parameterValue) {
            String filePath = MACkeyURL.getFile();
            Properties prop = new Properties();
            try {
                InputStream fis = new FileInputStream(filePath);
                // 從輸入流中讀取屬性列表(鍵和元素對)
                prop.load(fis);
                // 調用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。
                
    // 強制要求為屬性的鍵和值使用字符串。返回值是 Hashtable 調用 put 的結果。
                OutputStream fos = new FileOutputStream(filePath);
                prop.setProperty(parameterKey, parameterValue);
                // 以適合使用 load 方法加載到 Properties 表中的格式,
                
    // 將此 Properties 表中的屬性列表(鍵和元素對)寫入輸出流
                prop.store(fos, "Update '" + parameterKey + "' value");
            } catch (IOException e) {
                System.err.println("Visit " + filePath + " for updating "
                        + parameterKey + " value error");
                e.printStackTrace();
            }
        }
        

    3:根據key讀取propertis文件value值
        /**
         * 根據key讀取value
         * 
    @param filePath
         * 
    @param key
         * 
    @return 對應的值
         
    */
        public static String readValueByKey(String filePath, String key) {
            System.out.println("properties file is path : " + filePath);
            Properties props = new Properties();
            try {
                InputStream in = new BufferedInputStream(new FileInputStream(filePath));
                props.load(in);
                String value = props.getProperty(key);
                System.out.println(" --> " + key + "=" + value);
                return value;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
        
    4:讀取properties配置文件所有信息
        /**
         *  讀取properties的全部信息
         * 
    @param filePath
         * 
    @return
         
    */
        @SuppressWarnings("unchecked")
        public static void readPropertiesAll(String filePath) {
            System.out.println("properties file is path : " + filePath);
            Properties props = new Properties();
            try {
                InputStream in = new BufferedInputStream(new FileInputStream(filePath));
                props.load(in);
                Enumeration en = props.propertyNames();
                while (en.hasMoreElements()) {
                    String key = (String) en.nextElement();
                    String Property = props.getProperty(key);
                    System.out.println(" --> " + key + "=" + Property);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    posted on 2013-08-08 23:43 奮斗成就男人 閱讀(166) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: rh男男车车的车车免费网站| 亚洲天堂2016| 国产免费爽爽视频免费可以看| 亚洲成A∨人片天堂网无码| 亚洲国产天堂久久综合网站| CAOPORM国产精品视频免费| 亚洲AV中文无码乱人伦| 黄人成a动漫片免费网站| 国产免费牲交视频| 日日摸夜夜添夜夜免费视频| 亚洲精品成人在线| 亚洲精品黄色视频在线观看免费资源| 亚洲日韩精品一区二区三区无码| 中文精品人人永久免费| 午夜成年女人毛片免费观看| 亚洲美女在线国产| 中国videos性高清免费| 免费国产成人高清在线观看麻豆| 亚洲三级视频在线观看| 免费无码又爽又刺激高潮软件| 在线观看免费亚洲| 国产成人精品日本亚洲11| 欧洲黑大粗无码免费| 亚洲国产成人久久综合一 | 在线免费观看毛片网站| 久久亚洲精品无码av| 在线永久看片免费的视频| 久久久青草青青亚洲国产免观| 猫咪免费人成在线网站| 亚洲乱码中文字幕综合| 豆国产96在线|亚洲| 免费视频淫片aa毛片| 天堂亚洲免费视频| 久久久久亚洲AV无码麻豆| 成人免费视频小说| xxxxx做受大片视频免费| 亚洲熟伦熟女新五十路熟妇| 一区二区三区福利视频免费观看| 亚洲最大的成人网站| 最近2019中文免费字幕| 一级中文字幕乱码免费|