在文件的讀取和網絡的數據處理中,經常會在Byte和String 之間進行格式的轉換。
Byte[] 字節流轉換爲String對象:
fin=mContext.openFileInput("helloworld.txt");
int size=fin.available();
byte[]buffer=new byte[size];
while(fin.read(buffer)>0)
{
mResult+=new String(buffer,"utf-8");
}
字符串轉換爲字符流:
String content="dfsfs";
fout.write(content.getBytes("utf-8"));