夢幻之旅

          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 閱讀(2072) 評論(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

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

          主站蜘蛛池模板: 安远县| 商丘市| 许昌市| 湟中县| 江津市| 凤城市| 大宁县| 沈丘县| 湖南省| 花莲市| 赣榆县| 防城港市| 盐城市| 三门峡市| 壤塘县| 清水县| 保定市| 方山县| 东宁县| 兰溪市| 闸北区| 伊宁市| 裕民县| 应城市| 德清县| 温宿县| 三穗县| 无棣县| 浙江省| 通渭县| 陆丰市| 安图县| 屏山县| 东丰县| 灵山县| 澳门| 恩施市| 武夷山市| 安西县| 玉山县| 封开县|