https://mvnrepository.com/artifact/com.googlecode.juniversalchardet/juniversalchardet/1.0.3
=================================================================================================================
public String readEncoding(File file) throws IOException {
byte[] buf = new byte[4096];
java.io.FileInputStream fis = new java.io.FileInputStream(file);
UniversalDetector detector = new UniversalDetector(null);
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
detector.reset();
buf = null;
fis.close();
return encoding == null?"UTF-8":encoding;
}
=================================================================================================================