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