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

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

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

    yxhxj2006

    常用鏈接

    統(tǒng)計

    最新評論

    JAVA讀取Properties配置文件


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


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


     1:加載properties配置文件
      /**
         * 根據(jù)key從Properties對象中得到相應(yīng)的值
         * 
    @param key
         * 
    @return 對應(yīng)的值
         
    */
        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);
                // 調(diào)用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。
                
    // 強制要求為屬性的鍵和值使用字符串。返回值是 Hashtable 調(diào)用 put 的結(jié)果。
                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:根據(jù)key讀取propertis文件value值
        /**
         * 根據(jù)key讀取value
         * 
    @param filePath
         * 
    @param key
         * 
    @return 對應(yīng)的值
         
    */
        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 奮斗成就男人 閱讀(171) 評論(0)  編輯  收藏


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲天堂在线视频| 精品无码国产污污污免费| 久久久久亚洲AV无码专区网站 | 人人狠狠综合久久亚洲88| a毛片成人免费全部播放| 国产乱子影视频上线免费观看| 亚洲国产精品免费观看| 成年女人色毛片免费看| 亚洲中文字幕久久精品蜜桃| 国产又黄又爽又猛免费app| 亚洲伦理中文字幕| 妞干网在线免费观看| 亚洲AV无码一区二区一二区| 在线观看亚洲免费| 免费又黄又爽又猛大片午夜| 亚洲国模精品一区| 在线观看免费黄色网址| 亚洲a在线视频视频| **aaaaa毛片免费同男同女| 在线综合亚洲中文精品| 日韩免费高清视频网站| 免费人人潮人人爽一区二区| 亚洲伊人久久大香线蕉综合图片| 三上悠亚电影全集免费| 亚洲精品午夜视频| 免费毛片网站在线观看| 一级做a爰片久久免费| 亚洲国产精品嫩草影院在线观看| 免费精品无码AV片在线观看| 77777亚洲午夜久久多喷| 亚洲XX00视频| 久久久99精品免费观看| 亚洲色www永久网站| 亚洲第一区在线观看| 久久午夜羞羞影院免费观看| 亚洲熟妇无码av另类vr影视| 亚洲国产一区明星换脸| 亚洲黄色片免费看| 尤物视频在线免费观看| 67pao强力打造67194在线午夜亚洲 | 亚洲成av人片在线观看无码不卡|