1. 程式人生 > >Android中byte陣列與Sting的互相轉換

Android中byte陣列與Sting的互相轉換

1、string轉化為byte[]陣列

String str = "abcd";
byte[] bs = str.getBytes();

2、byte[]陣列轉化為string字串

/*String str1 = "abcd";
byte[] bs1 = str1.getBytes();*/
byte[] bs1 = {97,98,100};
String s = new String(bs1);

3、設定格式

byte[] srtbyte = {97,98,98};
String res = new String(srtbyte,"UTF-8");