`
hujing101
  • 浏览: 10391 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

判断文件编码

阅读更多
断文件编码
import java.io.File;
import java.nio.charset.Charset;

import info.monitorenter.cpdetector.io.CodepageDetectorProxy;
import info.monitorenter.cpdetector.io.JChardetFacade;


public class Test
{
    public static void main(String[] args)
    {
        CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
        detector.add(JChardetFacade.getInstance());
        
        Charset charset = null;
        
        File f = new File("C:/1.txt");  
        
        try 
        {   
            charset = detector.detectCodepage(f.toURL());   
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }   
        if(charset!=null)
        {   
            System.out.println(f.getName()+"编码是:"+charset.name());   
        }
        else  
            System.out.println(f.getName()+"未知");  
    }
    
}

分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics