首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JAVA 判断历程

2012-11-17 
JAVA判断进程public boolean getProcess(String proName) throws Exception {??? ??? Process p Runtime

JAVA 判断进程

public boolean getProcess(String proName) throws Exception {

??? ??? Process p = Runtime.getRuntime().exec("cmd /c tasklist");
??? ??? ByteArrayOutputStream baos = new ByteArrayOutputStream();
??? ??? InputStream os = p.getInputStream();
??? ??? byte b[] = new byte[1024];
??? ??? while (os.read(b) > 0) {
??? ??? ??? baos.write(b);
??? ??? }
??? ??? String s = baos.toString();
??? ??? if (s.indexOf(proName) >= 0) {
??? ??? ??? return true;
??? ??? } else {
??? ??? ??? return false;
??? ??? }

??? }

?

?

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

说明:这个方法是基于命令行的,所有你要保证的是cmd的命令能启用,要不然是不用不来的

热点排行