判断文件编码
断文件编码
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()+"未知"); } }