Home > Java > JavaBase > body text

Solution to string garbled characters in java

Release: 2019-12-11 17:22:32
Original
4313 people have browsed it

Solution to string garbled characters in java

Solution to string garbled code in java: (Recommended: java video tutorial)

Transcode the string to solve the string garbled code As follows:

System.out.println(str);
            String str1 = new String(str.getBytes("ISO-8859-1"), "utf-8");
            System.out.println(str1);
            String str2 = new String(str.getBytes("gb2312"), "utf-8");
            System.out.println(str2);
            String str3 = new String(str.getBytes("gbk"), "utf-8");
            System.out.println(str3);
Copy after login

str.getBytes(charsetName);charsetName is the encoding of the original character

"utf-8" converts str to utf-8 encoding.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Solution to string garbled characters in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!