[JAVA] IOException: Invalid byte 2 of 2-byte UTF-8 sequence (solution), ioexception2-byte

Source: Internet
Author: User

[JAVA] IOException: Invalid byte 2 of 2-byte UTF-8 sequence (solution), ioexception2-byte

Log printing is incomplete. Only the title exception information is printed in the background:

Previous log print information: log. debug (e. getMessage ());

Log. debug (e); log. debug (e. getStackTrace ());

The importance of log printing cannot only print messages

 

Find the cause of the problem. This problem occurs in the Payment Protection Function. After finding the cause on the Internet, the following Connection provides the most accurate information:

Http://blog.csdn.net/linkyou/article/details/3975491

 

The root cause is the following code:

public static InputStream String2Inputstream(String str) throws IOException {        return new ByteArrayInputStream(str.getBytes("UTF-8"));    }

Add the UTF-8 in getBytes. The root cause is that the encoding method on our server is GBK. At this time, when getBytes is obtained, the encoding method on the server is obtained, and an error is reported.

 

Conclusion: encoding is a key concern when string and binary stream conversion are involved anywhere. All encoding methods must be determined, rather than taken from the server, unified management of coding methods is king. At the same time, I can only sigh, but I am used to it ~


When xml parsing changes, Invalid byte 2 of 2-byte UTF-8 sequence

The landlord is a good guy, but it is estimated that no one birds you. Alas, it is better to believe in books than to have no books.

The error "orgxmlsaxSAXParseException" is reported during xml parsing:

Use the text editing tool to look at it with a UTF-8. Xml Error

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.