返回信息流在MyEclipse 8.5中,在控制台中输出的中文是正常的,而在eclipse中,输出却是乱码。。。。
代码如下:
public class Test {
public static void main(String args[])
{
String str;
InputStreamReader stdin = new InputStreamReader(System.in);//????????
BufferedReader bufin = new BufferedReader(stdin);
try
{
System.out.print ( "输入字符:");
str = bufin.readLine();
System.out.println ( "输入的字符为: "+str);
}
catch(IOException E)
{
System.out.println( "IO错误!!! ");
}
}
}
==================================================================================
MyEclipse执行结果:
输入字符:哈哈
输入的字符为: 哈哈
Eclipse
输入字符:哈哈
输入的字符为: 鍝堝搱
两个环境的text file encoding都是UTF-8
实在无解了。。。。。。。。。。。
这是一条镜像帖。来源:北邮人论坛 / java / #21226同步于 2012/1/7
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
[字符编码问题]同样的代码,在两个IDE结果不同
martinakm
2012/1/7镜像同步8 回复
订阅后,新回复会通过你的通知中心匿名送达。
8 条回复
大师!!!!!!!!!!!!!
【 在 martinakm (衣咦椅毅) 的大作中提到: 】
: 在MyEclipse 8.5中,在控制台中输出的中文是正常的,而在eclipse中,输出却是乱码。。。。
: 代码如下:
: public class Test {
: ...................
狼总,救我。。。。。。。。
【 在 wolfFN 的大作中提到: 】
: 大师!!!!!!!!!!!!!
: 【 在 martinakm (衣咦椅毅) 的大作中提到: 】
: : 在MyEclipse 8.5中,在控制台中输出的中文是正常的,而在eclipse中,输出却是乱码。。。。
: ...................
Run Configuration里改一下控制台编码试试
【 在 martinakm (衣咦椅毅) 的大作中提到: 】
: 在MyEclipse 8.5中,在控制台中输出的中文是正常的,而在eclipse中,输出却是乱码。。。。
: 代码如下:
: public class Test {
: ...................
我的工程是utf-8的,console编码也是utf-8
输入 阿奎罗
输出 阿奎#@!@#
后面就是一个乱码了。
但是输入 罗纳尔多
输出 罗纳尔多
就是正常的
【 在 ox 的大作中提到: 】
: Run Configuration里改一下控制台编码试试
: 【 在 martinakm (衣咦椅毅) 的大作中提到: 】
: : 在MyEclipse 8.5中,在控制台中输出的中文是正常的,而在eclipse中,输出却是乱码。。。。
: ...................
输入大师呢?
【 在 martinakm 的大作中提到: 】
: 我的工程是utf-8的,console编码也是utf-8
: 输入 阿奎罗
: 输出 阿奎#@!@#
: ...................
try to set the charset for InputStreamReader
use
public InputStreamReader(InputStream in, String charsetName)
instead
【 在 buptwhisper 的大作中提到: 】
: try to set the charset for InputStreamReader
: use
: public InputStreamReader(InputStream in, String charsetName)
: ...................
很有道理,文件的编码要与charsetName一致