Garbled is a very disgusting problem.
Windows and Linux read the TXT file, once read, the encoding changes, it can no longer restore, only restart the project.
Online there are many ways to read the file header, the method is very good, but the pro-test can not be used (8-bit right to judge 0xFF, take 3 bytes of -1,-2, in general, most of these two on the Internet).
Then stumbled upon a method, Charsetprinter.
This method requires the introduction of jar packages, which is very useful.
public static string guessencoding (string filename) { try {charsetprinter Charsetprinter = new Charsetprinter (); String encode = charsetprinter.guessencoding (new File (filename)); return encode; catch (Exception e) { throw new RuntimeException (e); } }
View Code
Need is Cpdetector_1.0.5.jar (search on the internet, a lot).
Gets the encoding that is encoded to read the workaround.