我是靠谱客的博主 隐形含羞草,这篇文章主要介绍处理使用ByteArrayOutputStream读取文件中文乱码情况,现在分享给大家,希望可以做个参考。

最开始:
ByteArrayOutputStream baos=new ByteArrayOutputStream();
int length=0;
byte[] buffer=new byte[1024];
while((length=is.read(buffer))!=-1){
baos.write(buffer, 0, length);
}
is.close();
baos.close();
Thread thread = new IPSErTask(baos.toString());
这样的处理会导致文件中的中文乱码。
解决方案如下:
将读取到的数据强制转化成UTF-8
ByteArrayOutputStream baos=new ByteArrayOutputStream();
int length=0;
byte[] buffer=new byte[1024];
while((length=is.read(buffer))!=-1){
baos.write(buffer, 0, length);
}
is.close();
baos.close();
byte[] lens = baos.toByteArray();20190312
String result = new String(lens,“UTF-8”);
Thread thread = new IPSErTask(result)
这样处理之后乱码问题就解决了。

最后

以上就是隐形含羞草最近收集整理的关于处理使用ByteArrayOutputStream读取文件中文乱码情况的全部内容,更多相关处理使用ByteArrayOutputStream读取文件中文乱码情况内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部