java如何获取本地操作系统进程列表
package com.wa.xwolf.sblog.util;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
public class ProcessUtil {
public static void main(String[] args) throws Exception {
// 创建系统进程
ProcessBuilder pb = new ProcessBuilder("tasklist");
Process p = pb.start();
BufferedReader out = new BufferedReader(new InputStreamReader(new BufferedInputStream(p.getInputStream()), Charset.forName("GB2312")));
BufferedReader err = new BufferedReader(new InputStreamReader(new BufferedInputStream(p.getErrorStream())));
System.out.println("Window 系统进程列表");
String ostr;
while ((ostr = out.readLine()) != null)
System.out.println(ostr);
String estr = err.readLine();
if (estr != null) {
System.out.println("\nError Info");
System.out.println(estr);
}
}
}
控制台输出:
以上就是本文的全部内容,希望大家可以熟练掌握java获取本地操作系统进程列表的方法。
以上是 java如何获取本地操作系统进程列表 的全部内容, 来源链接: utcz.com/p/208828.html