java 里面的string 和byte[] 怎么互转


public class TestBytes {

    private static String FORMAT = "UTF-8";
public static void main(String[] args) throws UnsupportedEncodingException {
byte[] bytes = new byte[] { 50, 0, -1, 28, -24 };
String sendString=new String( bytes ,FORMAT);
byte[] sendBytes= sendString.getBytes(FORMAT); String recString=new String(sendBytes ,FORMAT);
byte[] mybytes=recString.getBytes(FORMAT); for(int i = 0 ; i < mybytes.length ; i++){
System.out.print(" ");
System.out.print(mybytes[i ]);
}
} }

输出结果是: 50 0 -17 -65 -67 28 -17 -65 -67,为什么会不一样!?

FORMAT = "ISO-8859-1" 就可以了!

上一篇:uva 12587 二分枚举


下一篇:chrome调试hove等类似事件