梦幻之旅

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 阅读(2056) 评论(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

这个什么玩意?  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: