夢幻之旅

          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

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

          主站蜘蛛池模板: 喀喇| 龙游县| 文登市| 霍林郭勒市| 宁南县| 新营市| 仁寿县| 嵊州市| 八宿县| 仁怀市| 五大连池市| 依兰县| 东至县| 库伦旗| 烟台市| 易门县| 宁武县| 齐齐哈尔市| 改则县| 崇左市| 重庆市| 汝州市| 西盟| 伽师县| 迭部县| 屯留县| 南和县| 广河县| 瑞金市| 缙云县| 贵南县| 济南市| 怀柔区| 安化县| 久治县| 乌海市| 洪泽县| 柳州市| 阿克苏市| 古田县| 高州市|