Traditional Culture Encyclopedia - Tourist attractions - How to output UTF-8 encoded string using GB18030 in Java?

How to output UTF-8 encoded string using GB18030 in Java?

Java is very convenient for this kind of conversion

If the input is UTF8 bytes, use

String s=new String(utf8_bytes, "UTF-8") ; //utf8_bytes is of byte[] type

If the input is a string, return directly

String s=original.

When the output is converted to gb18030, there is no need to convert when not outputting.

os.write(s.getBytes("GB18030")); //os is the output stream