夢幻之旅

          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

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

          主站蜘蛛池模板: 噶尔县| 正阳县| 广灵县| 子洲县| 东港市| 赤峰市| 班玛县| 永福县| 保亭| 资中县| 大同县| 岱山县| 息烽县| 迭部县| 尚志市| 若尔盖县| 巴彦淖尔市| 内丘县| 黄骅市| 章丘市| 文登市| 金乡县| 丹凤县| 峨眉山市| 手机| 南通市| 沙田区| 鄂温| 营山县| 奉新县| 桦甸市| 曲阳县| 伊宁市| 贺州市| 沙河市| 平顶山市| 香河县| 利川市| 桑日县| 青浦区| 舞钢市|