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實現數組

相關文章
相關標籤/搜索