文本文件编码探测,修改
探测不到编码不做处理 文件内容较少时,一般都不准确
This commit is contained in:
@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user