美文网首页
Java执行cmd 中文

Java执行cmd 中文

作者: Jaesoon | 来源:发表于2017-10-11 17:47 被阅读138次
public static void main(String[] args) {
        try {
            // 执行ping命令
            Process process = Runtime.getRuntime().exec("cmd /c e:&dir");
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("GBK")));
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

相关文章

网友评论

      本文标题:Java执行cmd 中文

      本文链接:https://www.haomeiwen.com/subject/emowyxtx.html