Java implements the transfer of txt files in any coding mode to UTF-8 coding mode

This paper uses BufferedReader and bufferedwriter in JDK to transfer txt files of any coding mode to UTF-8 coding mode.

UTF-8 (8-bit Unicode transformation format) is a variable length character encoding for Unicode, also known as universal code. It was created by Ken Thompson in 1992. Now it has been standardized as RFC 3629. UTF-8 encodes Unicode characters with 1 to 6 bytes. It can be used on a web page to display Chinese simplified, traditional and other languages The biggest advantage of UTF-8 is that it can avoid the problem of garbled code.

This method first judges the encoding mode of TXT file, then reads it by line according to its encoding mode, and then writes it by line with UTF-8 encoding. The encoding method of TXT file is detected with the help of encodingdetect class.

Test code:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>