java如何获取本地操作系统进程列表
程序员文章站
2024-03-05 10:01:06
package com.wa.xwolf.sblog.util;
import java.io.bufferedinputstream;...
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获取本地操作系统进程列表的方法。
上一篇: Android仿斗鱼直播的弹幕效果