如题所述
1、string 转 byte[]
java">String str = "Hello";
byte[] srtbyte = str.getBytes();
2、byte[] 转 string
java">byte[] srtbyte;
String res = new String(srtbyte);
System.out.println(res);
3、设定编码方式相互转换
java">String str = "hello";
byte[] srtbyte = null;
try {
srtbyte = str.getBytes("UTF-8");
String res = new String(srtbyte,"UTF-8");
System.out.println(res);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java">String str = "Hello";
byte[] srtbyte = str.getBytes();
2、byte[] 转 string
java">byte[] srtbyte;
String res = new String(srtbyte);
System.out.println(res);
3、设定编码方式相互转换
java">String str = "hello";
byte[] srtbyte = null;
try {
srtbyte = str.getBytes("UTF-8");
String res = new String(srtbyte,"UTF-8");
System.out.println(res);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
温馨提示:答案为网友推荐,仅供参考