android 字符编码转换

来源:互联网 发布:嵌入式linux开机动画 编辑:程序博客网 时间:2024/05/20 14:26

在文件的读取和网络的数据处理中,经常会在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"));

原创粉丝点击