直接使用输出为乱码
Process proc;
try {
proc = Runtime.getRuntime().exec("ipconfig");
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream());
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
proc.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
改进,添加第二参数为GBK
Process proc;
try {
proc = Runtime.getRuntime().exec("ipconfig");
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(),"GBK"));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
proc.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}