package com.StringTest; import java.nio.charset.StandardCharsets; import java.util.Arrays; public class StringToByte { public static void main(String[] args) { String str1 = "abc123"; //String转byte[] byte[] bytes = str1.getBytes(StandardCharsets.UTF_8); System.out.println(Arrays.toString(bytes)); //byte[]转String String s = new String(bytes); System.out.println(s); } }