java中输入输出中文乱码,怎么办?

来源:百度知道 编辑:UC知道 时间:2024/05/30 17:29:34
import java.io.*;
public class test {

public static void main(String[] args)throws IOException{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
System.out.println(s);

}
}
////////////////////////////////////////////////////
每当输入中文就乱码
那个改成new InputStreamReader(System.in,"GB2312")也不行

解决办法:
1.在代码区域右键 -> run as -> run configurations -> common(右侧) -> console encoding
如果出现此错误,此时的编码格式应该是UTF-8,选择Other,这时可能没有GBK选项,如果没有,则执行之后操作。
2.更改该项目的文本文件编码,项目右键 -> properties -> resource -> 先将 text file encoding调整回GBK,然后再回去重新设置console encoding编码为GBK。

系统问题
你把所有的dos窗口关闭,然后开始-运行
输入
reg add "HKEY_CURRENT_USER\Console" /v "LoadConIme" /d 1 /t REG_DWORD /f

或者开始-运行-regedit
注册表中
HKEY_CURRENT_USER\Console下LoadConIme的值改为1

BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()), "utf-8");

You might want to change "utf-8" to "gb2312" to support GB encoding.

右键项目==》properties==》Resource==》修改字符集utf-8(Eclipse)