Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Java to convert strings between ISO-8859-1 and UTF-8

Shulou Source: shulou.com Published: 2022-06-02 07:29:14 09月30日 Update

This article mainly explains "how to use Java to convert strings between ISO-8859-1 and UTF-8", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to use Java to convert strings between ISO-8859-1 and UTF-8"!

We all know that in some special scenarios, we need to use a special encoding format, such as UTF-8, but the default encoding of the system is ISO-8859-1.

Then we need to convert the code to the coding format we need.

This is the problem I encountered today. I need to perform two encoding conversions on the string, so how do I do the related conversion?

Below, the author describes the use of Java code to convert strings between ISO-8859-1 and UTF-8, as follows:

The idea of realization is:

Use

GetBytes ("UTF-8")

Or

GetBytes ("ISO-8859-1")

A byte array that can be converted to a specified character encoding

The conversion between them is based on a string as a bridge.

Example:

Sharing examples of conversion between ISO-8859-1 and UTF-8

Package com.java265.other;public class Test {/ * * java265.com examples of conversion between encoding types are shared * * / public static void main (String [] args) throws Exception {String str = "java265.com"; byte [] latin1 = str.getBytes ("ISO-8859-1"); byte [] utf8 = new String (latin1, "ISO-8859-1"). GetBytes ("UTF-8") Latin1 = new String (utf8, "UTF-8") .getBytes ("ISO-8859-1") }} Thank you for your reading, the above is the content of "how to use Java to convert strings between ISO-8859-1 and UTF-8". After the study of this article, I believe you have a deeper understanding of how to use Java to convert strings between ISO-8859-1 and UTF-8. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: UTF-8 character inter-character string encoding learning special content idea format example question following two code scenario byte that is case array Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Microsoft Apple Docker