fix: #I7VP0I 检测文件编码时尝试所有可能顺序
This commit is contained in:
parent
c4b998100e
commit
f7505f6063
@ -36,10 +36,12 @@ public class EncodingDetector {
|
||||
CharsetDetector charsetDetector = new CharsetDetector();
|
||||
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file.getPath()))) {
|
||||
charsetDetector.setText(inputStream);
|
||||
CharsetMatch match = charsetDetector.detect();
|
||||
LOG.debug("{} : {}", match.getName(), match.getConfidence());
|
||||
if (match.getConfidence() > 50) {
|
||||
return match.getName();
|
||||
CharsetMatch[] matchList = charsetDetector.detectAll();
|
||||
for (CharsetMatch match : matchList) {
|
||||
LOG.debug("{} : {}", match.getName(), match.getConfidence());
|
||||
if (match.getConfidence() > 50) {
|
||||
return match.getName();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("", e);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user