做一个从windows cmd截获命令返回值的java程序,结果截回来的文字中所有的中文都是乱码
Microsoft Windows [�汾 6.1.7260]
��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ��
看了一下,问题出在BufferedReader上,原来的代码是:
- BufferedReader buffer = new BufferedReader(in);
BufferedReader buffer = new BufferedReader(in);
这样会出现编码的问题。我在bufferedReder后面加上了转换成utf-8的方法:
- BufferedReader buffer = new BufferedReader(
- new InputStreamReader(in,"utf-8"));
BufferedReader buffer = new BufferedReader( new InputStreamReader(in,"utf-8"));
发现还是乱码,试了其他一些编码,最终GBK和GB2312可以成功显示中文。
- BufferedReader buffer = new BufferedReader(
- new InputStreamReader(in,"GB2312"));