我的正常 ub = new String(s.getBytes("utf-8")).getBytes(); 以为utf-8为字符集构造新的string,然后用系统默认字符集转为byteub = new String(s.getBytes()).getBytes("utf-8"); 用系统默认字符集造新的string,然后用utf-8字符集转为byte
ub = new String(s.getBytes("utf-8")).getBytes(); 以为utf-8为字符集构造新的string,然后用系统默认字符集转为byteub = new String(s.getBytes()).getBytes("utf-8"); 用系统默认字符集造新的string,然后用utf-8字符集转为byte ------------------------------------------------ alaal(穷街)说得对
ub = new String(s.getBytes()).getBytes("utf-8");
分别的含义是什么?为什么第一个的结果不正确?
public class test
{
public static void main(String[] args)
{
String s;
try
{
s = "最后";
s=new String(s.getBytes("ISO-8859-1"),"utf-8"); //加上这个就ok了
byte[] ub = null; ub = s.getBytes("utf-8");
for (int i = 0; i < ub.length; i++)
{
System.out.print("(" + ub[i] + ")");
}
System.out.println(); ub = new String(s.getBytes("utf-8")).getBytes();
for (int i = 0; i < ub.length; i++)
{
System.out.print("(" + ub[i] + ")");
}
System.out.println();
}
catch (UnsupportedEncodingException e1)
{
}
}
}
ub = new String(s.getBytes("utf-8")).getBytes();
以为utf-8为字符集构造新的string,然后用系统默认字符集转为byteub = new String(s.getBytes()).getBytes("utf-8");
用系统默认字符集造新的string,然后用utf-8字符集转为byte
以为utf-8为字符集构造新的string,然后用系统默认字符集转为byteub = new String(s.getBytes()).getBytes("utf-8");
用系统默认字符集造新的string,然后用utf-8字符集转为byte
------------------------------------------------
alaal(穷街)说得对