解决方案 »

  1.   

    不会Linux啊,前几天无聊的时候,写着玩的,不知道对楼主有没有帮助
    try {
    // 获取所有进程
    Process process = Runtime.getRuntime().exec("tasklist");
    Scanner in = new Scanner(process.getInputStream());
    while (in.hasNextLine()) {
    String p = in.nextLine(); // p的效果
    // notepad.exe 1028 Console 1 6,884 K
    if (p.contains(PROCESS)) { StringBuffer buf = new StringBuffer();
    // buf的效果
    // notepad.exe1028Console16,884K
    for (int i = 0; i < p.length(); i++) {
    char ch = p.charAt(i);
    if (ch != ' ') {
    buf.append(ch);
    }
    }
    // 截出notepad.exe的PID
    int pid = Integer
    .parseInt(buf.toString().split("Console")[0]
    .substring(PROCESS.length()));
    // 强制结束进程
    Runtime.getRuntime().exec("taskkill /pid " + pid + " /f"); }
    }
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }楼主看看用Scanner 行不行