码迷,mamicode.com
首页 > 编程语言 > 详细

使用java对执行命令行 或 执行bat文件

时间:2015-01-15 19:54:28      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

public class Hellotianhao {
public static void main(String[] args) throws Exception{
	System.out.println("hello tianhao");
	Runtime.getRuntime().exec("cmd /k mkdir d:\\xutianhao");
}
}

运行结果是在d盘新建了一个名为xutianhao的文件夹

 

 

 

 

java执行bat文件  bat文件书写注意在每条命令之前都要加一条@

bat文件 

@e:
@ant

java文件

public class Hellotianhao {
public static void main(String[] args) throws Exception{
	
	
	Runtime.getRuntime().exec("E:\\firstbat.bat");
	
}
}

  通过使用这个java文件调用bat文件执行bat文件内的两条指令

1.先切换到e盘

2.再调用ant工具完成ant指令(删除dir文件)

 

构建文件build.xml

<?xml version="1.0"?>

<project name="targetStudy" default="deletedir">
<target name="deletedir" description="新建目录">
	<delete dir="newdir1"/>
</target>
</project>	

 

使用java对执行命令行 或 执行bat文件

标签:

原文地址:http://www.cnblogs.com/tianhao/p/4226895.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!