|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
以下代码在windows2000上可以运新哦。 SayHi.exe为任意的一个执行程序。 public static void main(String args[]) { String s = null; // system command to run String cmd = "cmd /c c:/SayHi.exe"; // set the working directory for the OS command processor File workDir = new File("c://"); try { Process p = Runtime.getRuntime().exec(cmd, null, workDir); int i = p.waitFor(); if (i == 0) { BufferedReader stdInput = new BufferedReader( new InputStreamReader(p.getInputStream())); // read the output from the command while ((s = stdInput.readLine()) != null) { System.out.println(s); } } else { BufferedReader stdErr = new BufferedReader( new InputStreamReader(p.getErrorStream())); // read the output from the command while ((s = stdErr.readLine()) != null) { System.out.println(s); } } } catch (Exception e) { System.out.println(e); } } 返回类别: 教程 上一教程: 关于Java的一些 工具,类库,框架...... 下一教程: Mini Java编译器(二) 您可以阅读与"Java调用系统执行程序(OS Command)"相关的教程: · 回答:为什么执行JAVA程序时,会出现Exception in thread"main" java.lang.NoClassDefFoundError的错?... · 如何在 Java 应用程序中读取 8 位和 24 位 Microsoft Windows 位图(转) · 利用Java调用可执行命令实例 · 如何将做好的JAVA程序生成可执行文件 · Java如何调用可执行文件和批处理命令 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |