读书人

判断资料编码

发布时间: 2012-07-02 17:46:23 作者: rapoo

判断文件编码
断文件编码

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()+"未知");      }    }

读书人网 >其他相关

热点推荐