Java character encoding and conversion

Source: Internet
Author: User

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.

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.