ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

JAVA,执行cmd命令控制台输出内容乱码问题解决

2021-07-14 01:03:22  阅读:275  来源: 互联网

标签:JAVA String ipconfig cmd 乱码 static java line public


现象如图:

 

 解决:

 

 

 

 代码如下:

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

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有