使用String类和字节数组进行编码转换
在Java中,可以通过String类的getBytes方法,将字符串转换成指定编码的字节数组,例如:byte[] bytes = str.getBytes("UTF-8");这样就能获取UTF-8编码的字节。若需要重新构造指定编码的字符串,可以用new String(bytes, "UTF-8");
使用String类和字节数组进行编码转换
在Java中,可以通过String类的getBytes方法,将字符串转换成指定编码的字节数组,例如:byte[] bytes = str.getBytes("UTF-8");这样就能获取UTF-8编码的字节。若需要重新构造指定编码的字符串,可以用new String(bytes, "UTF-8");