`
emowuyi
  • 浏览: 1478552 次
文章分类
社区版块
存档分类
最新评论

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"));

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics