用到工具 icu4j
可到官网自行下载 点这里
API路径 :CharsetDetector API
我的网盘也有,大家也可以下载,链接: https://pan.baidu.com/s/11CBdMyjS9s6k26y6LiBpWA 提取码: h9hi
public static String guessEncoding(byte[] bytes) {
CharsetDetector detector = new CharsetDetector();
detector.setText(bytes);
CharsetMatch match = detector.detect();
String code = match.getName();
return code;
}
只通过以上几段代码即可实现。