Java在Mac OS X终端(Terminal.app)下 system.out.print 乱码的问题
Mac OS X下Terminal默认编码为MacRoman,会产生乱码
测试:System.out.println(“这是一个中文字串”);
解决方法
1.运行时加入参数Dfile.encoding:
java -Dfile.encoding=UTF8 ClassName
PrintStream out = null;try { out = new PrintStream(System.out, true, "UTF-8");} catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace();}out.println("这是一个中文字串");
Properties properties = System.getProperties();System.out.println(properties.getProperty("file.encoding"));