现在的位置: 首页 > 综合 > 正文

java调用本地程序

2018年08月14日 ⁄ 综合 ⁄ 共 669字 ⁄ 字号 评论关闭

      例一:

      try {
            Runtime rt = Runtime.getRuntime();
            Process p = rt.exec("systeminfo");
            InputStreamReader ir = new InputStreamReader(p.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String line;
            while ((line = input.readLine()) != null) {
                System.out.println(line);
            }
        } catch (java.io.IOException e) {
            System.err.println("IOException " + e.getMessage());
        }

        例二:

        Runtime rt = Runtime.getRuntime();
        try {
            Process p = rt.exec("notepad");
        } catch (IOException ex) {
            Logger.getLogger(ZipOp.class.getName()).log(Level.SEVERE, null, ex);
        }

抱歉!评论已关闭.