Java系列之:byte[]和string之间的转换
一、String转化为byte[]
//Original String
String string = "hello world";
//Convert to byte[]
byte[] bytes = string.getBytes();
System.out.println("bytes输出是:"+bytes);
输出如下所示:
bytes输出是:[B@43a0cee9
二、byte[]转化为string
//Convert back to String
//byte[] bytes
String s = new String(bytes);
//Check converted string against original String
System.out.println("Decoded String : " + s);
输出如下所示:
Decoded String : hello world