android 字符編碼轉換

在文件的讀取和網絡的數據處理中,經常會在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"));

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章