用UTF8编码读入一个utf8的文件,结果写入输出流的时候还是乱码?这是怎么回事?
InputStream ist = LaucherTest.class.getResourceAsStream("/Book1.csv");
InputStreamReader reader = new InputStreamReader(ist,"UTF-8");
ByteArrayOutputStream str= new ByteArrayOutputStream();
int ch;
while((ch=reader.read())!=-1){
str.write(ch);
}
查看str内容,结果还是乱码 :!:
为什么以UTF8格式读取UTF8格式文件,写入输出流后还是乱码
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
jinnianshilongnian 2012-09-06 12:20关注nputStreamReader reader = new InputStreamReader(ist,"UTF-8");
ByteArrayOutputStream str= new ByteArrayOutputStream();
int ch;
while((ch=reader.read())!=-1){
str.write(ch);
}Reader读/Writer写 字符
InputStream读/OutputStream写 字节
它们要配套使用现在你混用了。把ByteArrayOutputStream改成OutputStreamWriter
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报