Java character encoding and conversion
During development, character encoding often causes headaches. Various garbled characters often occur. The following describes the java encoding conversion and common garbled characters used for reading:
First look at an image:
Let's take a look at how to handle encoding conversion in java:
Package com. test;/*** string encoding conversion * @ author Herman. xiong * @ date July 16, 2015 09:36:59 * @ version V3.0 * @ since Tomcat6.0, Jdk1.6 * @ copyright Copyright (c) 2015 */public class HttpServerDecoder {public static void main (String [] args) throws Exception {String str = "welcome to join the request group: 454796847 join us! "; System. out. println (str); // convert to UTF-8 to output System. out. println (new String (. getBytes ("UTF-8"); // converts it to gbk and outputs the System. out. println (new String (. getBytes ("gbk"); // converts a ISO-8859-1 to a utf-8System.out.println (new String (str. getBytes ("ISO-8859-1"), "UTF-8 "));}}
Welcome to my blog! If you have any questions, please join the QQ group: 454796847 to learn together!
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.