Java ファイルの文字コードを判別する
JISAutoDetect
juniversalchardet
public static String detectFileEncoding(File file) throws IOException { String result = null; byte[] buf = new byte[4096]; FileInputStream fis = new FileInputStream(file); UniversalDetector detector = new UniversalDetector(null); int nread; while ((nread = fis.read(buf)) > 0 && !detector.isDone()) { detector.handleData(buf, 0, nread); } detector.dataEnd(); result = detector.getDetectedCharset(); detector.reset(); return result; }
YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto
Copyright© 矢木 浩人 All Rights Reserved.