Java的中文处理 - String转换bytes和bytes转String

import java.io.UnsupportedEncodingException; class DataProcess { public static byte[] stringToBytes(String str) { try { // 使用指定的字符集将此字符串编码为byte序列并存到一个byte数组中
            return str.getBytes("utf-8"); } catch (UnsupportedEncodingException e) {
 e.printStackTrace(); } return null; } public static String bytesToString(byte[] bs) { try { // 经过指定的字符集解码指定的byte数组并构造一个新的字符串
            return new String(bs, "utf-8"); } catch (UnsupportedEncodingException e) {
 e.printStackTrace(); } return null; } }

 

参考:html

1)java中怎么从byte字节流转换为中文java

2)中文转unicode,中文转bytes,unicode转bytes java实现数组

相关文章
相关标签/搜索