import java.io.UnsupportedEncodingException;
import java.util.Arrays;
public class Main {
public static void main(String[] args)
{
try
{
String s = "s";
System.out.println( Arrays.toString( s.getBytes("utf8") ) );
System.out.println( Arrays.toString( s.getBytes("utf16") ) );
System.out.println( Arrays.toString( s.getBytes("utf32") ) );
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
}
}
控制台:
[115]
[-2, -1, 0, 115]
[0, 0, 0, 115]
它是什么?
[-2,-1]-???
此外,我指出,如果我这样做:
String s = new String(new char[]{ u1251 });
System.out.println( Arrays.toString( s.getBytes("utf8") ) );
System.out.println( Arrays.toString( s.getBytes("utf16") ) );
System.out.println( Arrays.toString( s.getBytes("utf32") ) );
控制台:
[-31, -119, -111]
[-2, -1, 18, 81]
[0, 0, 18, 81]