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

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

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

    隨筆-9  評論-15  文章-1  trackbacks-0
        用Java寫properties文件時(shí),如果直接用setProperties和store方法往FileOutputStream寫,寫出來的東西面目全非了。沒有正確的格式。因此我使用了這個(gè)方法來寫,一行一行的讀。一行一行地寫。
      1/**
      2   * write property.
      3   * @param title parameter defined in properties file
      4   * @param key parameter defined title value
      5   * @return String return value
      6   */

      7  String writeProp(String filePath, String fileName, String title, String key,
      8                   Logger logger) {
      9
     10    String strResult = "";
     11    String pathAddFile = ""//write file with path and name
     12    String tempFile = "";
     13    String strTemp = ""//use for identify if the modify is success
     14    //filePath is null the file in the default path ,else file in the filePath+\+fileName
     15    if (filePath.equals("")) {
     16      pathAddFile = fileName;
     17      tempFile = "temp.properties";
     18    }

     19    else {
     20      pathAddFile = filePath + systemSeparator + fileName;
     21      tempFile = filePath + systemSeparator + "temp.properties";
     22    }

     23    //properties file
     24    File aFile = new File(pathAddFile);
     25    //temp file
     26    File tFile = new File(tempFile);
     27    if (!aFile.exists()) {

     31      strResult = "error";
     32      return strResult;
     33    }

     34    //set property to properties
     35    try {
     36      FileReader fr = new FileReader(pathAddFile);
     37
     38      BufferedReader br = new BufferedReader(fr);
     39      try {
     40        FileWriter fw = new FileWriter(tempFile);
     41        PrintWriter out = new PrintWriter(fw);
     42
     43        String strLine = br.readLine().trim();
     44        while (strLine != null{
     45          //identify if strLine have title,have change key
     46          if (strLine.startsWith(title)) {
     47            strLine = title + "=" + key;
     48            strTemp = "1";
     49          }

     50          out.write(strLine);
     51          out.println();
     52          out.flush();
     53          //read next line
     54          strLine = br.readLine();
     55        }

     56        fw.close();
     57        out.close();
     58        //close BufferedReader object
     59        br.close();
     60         //close file
     61        fr.close();
     62        //delete properties file
     63        if (aFile.exists()) {
     64          if (!aFile.delete()) {
     68            return "error";
     69          }

     70        }

     71        //rename temp file to properties file
     72        if (!tFile.exists()) {
     76          return "error";
     77        }

     78        tFile.renameTo(aFile);
     79        if (!strTemp.equals("1")) {
     80          //there is no title prop exit so modify failed
     85          strResult = "error";
     86
     87        }

     88        return strResult;
     89      }

     90      catch (IOException ex2) {
     91        ex2.printStackTrace();
     92        strResult = "error";
     93        logger.fatal(
     94            "CmnEToyotaExtractProp ----- writeProp ----- failed !");
     95        return strResult;
     96
     97      }

     98    }

     99    catch (FileNotFoundException ex1) {
    100      ex1.printStackTrace();

    103      strResult = "error";
    104      return strResult;
    105    }

    106
    107  }
       該方法實(shí)現(xiàn)了對屬性文件參數(shù)的修改。
    posted on 2005-08-02 15:41 jam 閱讀(5182) 評論(0)  編輯  收藏

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 在线免费观看色片| 国产在线98福利播放视频免费| 亚洲视频在线观看网站| 三年片在线观看免费观看高清电影 | 羞羞视频网站免费入口| 亚洲人成网7777777国产| 久久精品免费一区二区| 菠萝菠萝蜜在线免费视频| 中文字幕亚洲综合久久| 免费日本黄色网址| 日韩精品无码一区二区三区免费| 亚洲中文字幕一二三四区| 亚洲中文字幕无码一区二区三区| 97免费人妻无码视频| 久久免费99精品国产自在现线| 亚洲一区中文字幕在线观看| 精品亚洲一区二区三区在线观看| 999久久久免费精品国产| 人与动性xxxxx免费| 国产.亚洲.欧洲在线| 亚洲精品成人无码中文毛片不卡 | 亚洲成AV人片在线观看WWW| 成人免费视频一区| 一级毛片免费不卡在线| 免费观看又污又黄在线观看| aa毛片免费全部播放完整| 亚洲AV无码乱码麻豆精品国产| 亚洲中文字幕久久精品无码APP| 在线看片无码永久免费视频| 手机看片国产免费永久| 老外毛片免费视频播放| 亚洲欧洲日韩极速播放| 久久精品蜜芽亚洲国产AV| 亚洲综合色自拍一区| 国产免费黄色大片| 成人无遮挡裸免费视频在线观看| 男人的天堂网免费网站| 国产免费久久精品99久久| 边摸边吃奶边做爽免费视频网站 | 亚洲黄色免费网址| 亚洲国产精品高清久久久|