输出txt文件的中文乱码怎么解决,急

cooldee 2004-12-02 04:27:14
String hello = "你好";
FileOutputStream out = new FileOutputStream("d:/data.txt");
if (out != null) {
for (int i = 0; i < hello.length(); i++) {
out.write(hello.charAt(i));
}
out.close();
}

string中的中文在txt文件中都成了乱码,怎么办?
...全文
126 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cooldee 2004-12-02
  • 打赏
  • 举报
回复
搞定了
两位见笑了
cooldee 2004-12-02
  • 打赏
  • 举报
回复
str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
没用啊

FileWriter能具体说一下吗
unat 2004-12-02
  • 打赏
  • 举报
回复
用FileWriter
vbscript1981 2004-12-02
  • 打赏
  • 举报
回复
你最好是能对String hello = "你好";
对它进行内码转换下。str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
cooldee 2004-12-02
  • 打赏
  • 举报
回复
help

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧