文本文件编码探测,修改

探测不到编码不做处理
文件内容较少时,一般都不准确
pull/1/head
HWliao 2017-12-25 16:55:23 +08:00 committed by klboke
parent fdf66b60ec
commit f05fea51a9
1 changed files with 3 additions and 1 deletions

View File

@ -169,7 +169,9 @@ public class DownloadUtils {
String encoding = null; String encoding = null;
try { try {
FileCharsetDetector.Observer observer = FileCharsetDetector.guessFileEncoding(sourceFile); FileCharsetDetector.Observer observer = FileCharsetDetector.guessFileEncoding(sourceFile);
encoding = observer.getEncoding(); // 为准确探测到编码,不适用猜测的编码
encoding = observer.isFound()?observer.getEncoding():null;
// 为准确探测到编码,可以考虑使用GBK 大部分文件都是windows系统产生的
} catch (IOException e) { } catch (IOException e) {
// 编码探测失败, // 编码探测失败,
e.printStackTrace(); e.printStackTrace();