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

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

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

    隨筆-77  評論-5  文章-2  trackbacks-0

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PushbackInputStream;
    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;

    public class UtfTool
    {

        /**
         * ant 編譯之后的result文件,注意要編譯提示錯誤的文件名要在同一行
         * 可以設置命令提示窗口的緩沖區大小實現
         * @param resultFileName
         */
        public static Set getFileNamesFromCompileResult(String resultFileName)
         throws java.io.IOException
        {
     Set<String> set = new HashSet();
     BufferedReader reader = new BufferedReader(new FileReader(
      resultFileName));
     String start = "[javac] ";
     int startLen = start.length();
     String end = ".java:";
     int endLen = end.length();
     
     String errMsg = "\\65279";
     while (reader.ready())
     {
         String line = reader.readLine();
         int indexStart = line.indexOf(start);
        
         if(line.indexOf(errMsg) == -1)
         {
      continue;
         }
         if (indexStart != -1)
         {
      int indexEnd = line.indexOf(end);
      if (indexEnd != -1)
      {
          String name = line.substring(indexStart + startLen,
           indexEnd + endLen - 1);
          set.add(name.trim());
      }
         }
     }
     return set;

        }
       
        /**
         * 讀取流中前面的字符,看是否有bom,如果有bom,將bom頭先讀掉丟棄
         * @param in
         * @return
         * @throws IOException
         */
        public static InputStream getInputStream(InputStream in) throws IOException
        {

     PushbackInputStream testin = new PushbackInputStream(in);
     int ch = testin.read();
     if (ch != 0xEF)
     {
         testin.unread(ch);
     } else if ((ch = testin.read()) != 0xBB)
     {
         testin.unread(ch);
         testin.unread(0xef);
     } else if ((ch = testin.read()) != 0xBF)
     {
         throw new IOException("錯誤的UTF-8格式文件");
     } else
     {
         //不需要做,這里是bom頭被讀完了
        //// System.out.println("still exist bom");

     }
     return testin;

        }
       
       
       
        /**
         * 根據一個文件名,讀取完文件,干掉bom頭。
         * @param fileName
         * @throws IOException
         */
        public static void trimBom(String fileName) throws IOException
        {

     FileInputStream fin = new FileInputStream(fileName);
     //開始寫臨時文件
     InputStream in = getInputStream(fin);
     String tmpFileName = fileName + ".tmp";
     FileOutputStream out = new FileOutputStream(tmpFileName);
     byte b[] = new byte[4096];

     int len = 0;
     while (in.available() > 0)
     {
         len = in.read(b, 0, 4096);
         out.write(b, 0, len);
     }

     in.close();
     fin.close();
     out.close();

     //臨時文件寫完,開始將臨時文件寫回本文件。
     in = new FileInputStream(tmpFileName);
     System.out.println("[" + fileName + "]");
     out = new FileOutputStream(fileName);

     while (in.available() > 0)
     {
         len = in.read(b, 0, 4096);
         out.write(b, 0, len);
     }
     in.close();
     out.close();
        }

        /**
         * 根據ant編譯錯誤來去除bom
         * @param resultFile
         * @throws IOException
         */
        static void trimBomByCompileResult(String resultFile) throws IOException
        {
     Set<String> set = getFileNamesFromCompileResult(resultFile);
     for (String fName : set)
     {
         trimBom(fName);
     }
        }

        public static void main(String[] args) throws IOException
        {
     trimBomByCompileResult("c:/result3.txt");
     
     ///List<String> list = getFileNamesFromCompileResult(resultFile);

    // InputStream in = new FileInputStream(
    //  "D:/cc/SSB_SRC_DEV_lijinglin2/TP_SSB/SSB_CJ203_Component/ProductCode/com/zte/ssb/component/access/implementation/dao/ImplementationDAO.java");
    // getInputStream2(in);
    // in.close();
        }
    }


    文章來源:http://stocknewbie.bokee.com/viewdiary.22061282.html
    posted on 2009-05-01 10:52 huohuo 閱讀(1859) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 久久久久久久91精品免费观看| 久久久久久毛片免费看| 免费看片在线观看| 久久亚洲AV无码精品色午夜麻| 两个人看的www免费视频| 国产亚洲精品AA片在线观看不加载| 国产成人+综合亚洲+天堂| 免费真实播放国产乱子伦| 色偷偷亚洲男人天堂| 亚洲高清无码专区视频| 国产成人无码免费网站| 亚洲色欲久久久综合网东京热| 国产猛男猛女超爽免费视频| 亚洲av无码一区二区三区不卡 | 亚洲∧v久久久无码精品| 91精品手机国产免费| 亚洲国产福利精品一区二区| 毛色毛片免费观看| 青草青草视频2免费观看| 亚洲一区二区三区在线观看精品中文| a级在线观看免费| 亚洲精品国产情侣av在线| 午夜视频在线观看免费完整版| 羞羞漫画登录页面免费| 亚洲成a人片77777kkkk| 一二三四免费观看在线视频中文版| 国产亚洲美女精品久久久久| 亚洲线精品一区二区三区| 中文字幕免费在线观看| 99亚洲男女激情在线观看| 亚洲Av永久无码精品三区在线| 91香蕉成人免费网站| 色www免费视频| 亚洲精品一卡2卡3卡三卡四卡| 国产大片51精品免费观看| 国产成人AV免费观看| 涩涩色中文综合亚洲| 亚洲国产一成人久久精品| 18禁成年无码免费网站无遮挡| 国产精品福利片免费看| 亚洲欧洲日产专区|