请问一个乱码的问题。急急急!!

shmilyfan 2004-11-05 01:33:38
PrintWriter的write把一字符串输出到TXT文本。但在服务器上,中文字都变成了乱码。请问谁能帮帮我。怎么来解决。
...全文
115 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
j2nix 2004-11-08
  • 打赏
  • 举报
回复
深入剖析Java编程中的中文问题及建议最优解决方法:
http://dev.csdn.net/develop/article/27/27140.shtm
http://dev.csdn.net/develop/article/27/27142.shtm

Java 繁体中文处理完全攻略(蔡学镛)
http://www.csdn.net/develop/author/cxy/java_big5_1.shtm
http://www.csdn.net/develop/author/cxy/java_big5_2.shtm
mxlmwl 2004-11-08
  • 打赏
  • 举报
回复
在设置读出流的时候就开始进行转码处理,不要在读出的时候边读边进行转码。
hvbird 2004-11-06
  • 打赏
  • 举报
回复
UTF-8,我在一本书上看到,也是这样说的,但不知道为什么,谁能解释解释啊!
yingyi8989 2004-11-05
  • 打赏
  • 举报
回复
上面说的都对,我原来碰过这样的问题,是这样子解决的。
tangyongtgyg 2004-11-05
  • 打赏
  • 举报
回复
在类中写这两个方法中的任一个,调用就可以啦!

public static String getGbcode(String str)
{
if(str == null)
return "";

try
{
byte[]bytesStr = str.getBytes("ISO-8859-1");
return new String(bytesStr,"GBK");
}
catch(Exception ex)
{
return str;
}
}

public static String getUnicode(String str)
{
if(str == null)
return "";

try
{
byte[]bytesStr = str.getBytes();
return new String(bytesStr,"ISO-8859-1");
}
catch(Exception ex)
{
return str;
}
}
xdev 2004-11-05
  • 打赏
  • 举报
回复
统统使用UTF-8 格式
tsingien 2004-11-05
  • 打赏
  • 举报
回复
如果同样的程序在某个地方可以,在另外一个地方不可以的话,可能是编码集的问题
qukmei 2004-11-05
  • 打赏
  • 举报
回复
String aa="中文内容";
aa=new String(aa.getBytes("ISO8859_1");
jinfanzi 2004-11-05
  • 打赏
  • 举报
回复
public String getStr(String str)
{
try
{
if (str == null)
{
return "-";
}
String temp_p=str;
String temp="";
temp=new String(temp_p.getBytes("ISO8859_1"),"GBK").trim();
//return temp;
return temp_p;
}
catch(Exception e)
{
System.out.println("get str exception: " + e.toString());
return "null";
}
}
alaal 2004-11-05
  • 打赏
  • 举报
回复
String aa="中文内容";
aa=new String(aa.getBytes("ISO-8859-1"),"GB2312");
Arias 2004-11-05
  • 打赏
  • 举报
回复
自己可以根据你的现实需要来进行对输出的String来进行中文编码的处理!

62,615

社区成员

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

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