1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
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获取本地操作系统进程列表的方法。