`

Eclipse中输入汉语, 读取出来乱码

 
阅读更多
InputStreamReader reader = new InputStreamReader(System.in,"UTF-8");
String name = new BufferedReader(reader).readLine();

Scanner scanner = new Scanner(System.in, "UTF-8");
String id = scanner.nextLine();

我在console中输入中文后,每次读出来都乱码,
网上查了下说设置workplace的编码和run configuration中common的编码
我都试过了(都已经改为 utf-8)。
用system.out.println(System.getProperty("file.encoding"));打印出来的结果也是 utf-8。
注:我一般将整个Eclipse环境设置成UTF-8编码格式。

--------------------解决方案--------------------
1)、关闭Eclipse。

2)、eclipse.exe同目录下eclipse.ini加一句:
-Dfile.encoding=utf-8
保存 eclipse.ini

3)、再打开Eclipse
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics