java 调用系统可执行程序
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class RunDosCommand {
public static void main(String[] args) throws IOException {
String cmd = "ipconfig";
Runtime run = Runtime.getRuntime();
Process p = run.exec(cmd);
BufferedInputStream in = new BufferedInputStream(p.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String s;
while ((s = br.readLine()) != null)
System.out.println(s);
}
}
输出结果:
Windows IP Configuration
Ethernet adapter 區域連線:
Connection-specific DNS Suffix . : iacp.iac
IP Address. . . . . . . . . . . . : 10.162.54.45
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.162.54.1
Ethernet adapter 無線網路連線:
Media State . . . . . . . . . . . : Media disconnected
Ethernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.56.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
输出的结果因电脑的不同,而不相同。
注:这样的情况下,是不会有Dos窗口弹出的。
public class RunDosCommand {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String path = System.getProperty("user.dir")+"/command/d.bat";
Runtime run = Runtime.getRuntime();
Process process = run.exec("cmd.exe /c start "+path);
}
}
执行d.bat中的命令。
相关文档:
1.拆分字符串
遇到特殊字符,比如:对‘$’符号,就应该使用‘\\$’,后总结可以加个方括号如 "[.]"。
2.遍历HASHMAP
Iterator itr = map.keySet().itrator();
while(itr.hasNext())
{
Object temp1 = itr.next();
Object temp2 = tab.get(temp1);
}
......
1.String str = new String("abc"); 请问定义了几个对象。定义了两个对象,一个"abc", 一个是new String().<String s = "abc";首先到堆中查找值为"abc"的对象,没有就新建一个对象,"abc"本身就是一个对象。>
2.面向对象的东西:abstract & interface的各自的作用,区别。
3.面向对象的特征,以及怎么实现的。1 ......
谈谈Java继承中的重载,覆盖和隐藏
好久不写博客了,距离上一篇已经过了两年多了。这两年在干嘛,总之一年难尽!
前一段时间忙了两个月,忙着研究和做一些SSH架构的东西,两个月下来,收获颇丰,最近闲下来了,于是就痛快的开始玩游戏,但是不知怎么地,怎么玩都没意思,于是决定开始再好好研究研究Java吧。于是大概翻了翻 ......
自己在公司网站开发总用DWR开发的一个简单聊天
本人也是在网站开发地图时有到了这个技术,刚学习DWR半个月
就把随手写的一个简单聊天来给大家共享,切磋一下。
由于考虑到某些局部原因,只发表了一些重要技术方面的资料,没有把全部东西共享。请个人体谅。
由于DWR2.0有个Bug ,我用的DWR1.0,但是,它必须用JDK1.4
......