<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)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲第一中文字幕| 亚洲色成人WWW永久网站| 亚洲高清不卡视频| 精品国产污污免费网站| 亚洲女同成av人片在线观看| 久久久久免费视频| 亚洲线精品一区二区三区| 中文字幕免费视频精品一| 亚洲乱码无码永久不卡在线| 中国一级特黄的片子免费 | 国产成人免费爽爽爽视频| 亚洲综合久久一本伊伊区| 成全视频免费高清| 青青青亚洲精品国产| 亚洲国产天堂久久综合| 国产一卡二卡3卡四卡免费| 久久亚洲AV无码西西人体| jizz18免费视频| 亚洲成A∨人片在线观看不卡| 久久免费视频99| 亚洲男女一区二区三区| AV片在线观看免费| 在线观看亚洲免费| 亚洲精品国产精品乱码视色| 国产午夜精品免费一区二区三区 | 亚洲国产精品成人综合久久久 | 久久精品无码一区二区三区免费| 午夜在线a亚洲v天堂网2019| 免费va在线观看| 四虎成人精品永久免费AV| 亚洲国产精品乱码在线观看97| 国产成人免费爽爽爽视频| a毛片成人免费全部播放| 亚洲国产精品久久久久婷婷软件| 国产电影午夜成年免费视频 | CAOPORN国产精品免费视频| 久久久久亚洲av无码专区| 日本不卡免费新一二三区| 丝袜足液精子免费视频| 四虎必出精品亚洲高清| 一本久久a久久精品亚洲|