PHP笔记网

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2018-09-17 16:33:12  修改时间:2024-10-24 14:56:24  分类:07.Java基础  编辑
public static void main(String[] args) {
    String keyWord = "chrome.exe";

    Runtime runtime = Runtime.getRuntime();

    try {
        Process process = runtime.exec("cmd /c Tasklist");

        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));

        String s;
        while ((s = in.readLine()) != null) {
            s = s.toLowerCase();
            if (s.startsWith(keyWord)) {
                System.out.println("==========>" + keyWord);
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}