The ultimate solution for reading garbled files under Windows and Linux!

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.