在文件的读取和网络的数据处理中,经常会在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"));
本文探讨了在文件读取和网络数据处理中,如何在Byte和String之间进行格式转换,包括从Byte[]到String的转换及从String到字符流的转换过程。
1772

被折叠的 条评论
为什么被折叠?



