夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
              識別字符串的編碼集,是一個讓人很頭痛的問題.
          /**
           * <p>
           * 本類用來探測字符的編碼集,關返回其名稱
           * </p>
           * 
           * 
          @author 惠萬鵬
           * @vision 1.08.08.06
           
          */
          public class Detector
          {
              
          private static CodepageDetectorProxy detectorProxy;
              
          static
              {
                  detectorProxy 
          = CodepageDetectorProxy.getInstance();
                  detectorProxy.add(JChardetFacade.getInstance());
              }
              
              
          public static synchronized String getEncodingType(String content)
                      
          throws IllegalArgumentException, IOException
              {
                  ByteArrayInputStream stream 
          = new ByteArrayInputStream(content
                          .getBytes());
                  
          return Detector.getEncodingType(stream, content.length());
              }
              
              
          public static synchronized String getEncodingType(File file)
                      
          throws MalformedURLException, IOException
              {
                  
          return detectorProxy.detectCodepage(file.toURL()).name();
              }
              
              
          public static synchronized String getEncodingType(InputStream inputStream,
                      
          int length) throws IllegalArgumentException, IOException
              {
                  
          return detectorProxy.detectCodepage(inputStream, length).name();
              }
          }
              如果朋友們有更好的方法,請賜教.^0^


          posted on 2008-08-06 10:30 HUIKK 閱讀(2074) 評論(3)  編輯  收藏 所屬分類: Java

          評論

          # re: 識別 字符串編碼集 2008-08-06 11:10 guest
          CodepageDetectorProxy 這個類的源碼在哪里????  回復  更多評論
            

          # re: 識別 字符串編碼集[未登錄] 2008-08-06 11:51 chinajj
          @guest
          import cpdetector.io.CodepageDetectorProxy;
          http://cpdetector.sourceforge.net/
            回復  更多評論
            

          # re: 識別 字符串編碼集 2008-08-07 11:12 fantasy
          CodepageDetectorProxy

          這個什么玩意?  回復  更多評論
            

          主站蜘蛛池模板: 庄河市| 宁夏| 崇礼县| 南川市| 蓝山县| 贡山| 巴东县| 闻喜县| 安仁县| 临猗县| 宜宾县| 孟村| 高平市| 九江县| 临沭县| 洛浦县| 平乐县| 久治县| 山阳县| 林芝县| 綦江县| 交城县| 邢台县| 罗田县| 东光县| 马关县| 南昌市| 惠水县| 砀山县| 潜江市| 金山区| 深水埗区| 清涧县| 于都县| 台中市| 肇庆市| 洛扎县| 民勤县| 札达县| 平凉市| 永年县|