快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

Java调用系统执行程序(OS Command)

以下代码在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如何调用可执行文件和批处理命令
    微笑服务 优质保证 索取样品