JAVA,执行cmd命令控制台输出内容乱码问题解决
作者:互联网
现象如图:
解决:
代码如下:
package com.java.app01; import java.io.*; public class ExecuteCmd { public static void main(String[] args){ executCmd(); } public static void executCmd(){ Runtime runtime = Runtime.getRuntime(); try { Process ipconfig = runtime.exec("ipconfig"); InputStream inputStream = ipconfig.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"GBK"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line; while ((line=bufferedReader.readLine()) !=null){ System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } }
标签:JAVA,String,ipconfig,cmd,乱码,static,java,line,public 来源: https://www.cnblogs.com/xiamaojjie/p/15009075.html