我是一名新手,对Java和Windows都不熟悉。我想要结束运行在特定端口上的进程,比如说9090。
我尝试过:
try{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("netstat -ano | findstr 9090");
BufferedReader stdInput = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
String s = null;
if ((s = stdInput.readLine()) != null) {
int index=s.lastIndexOf(" ");
String sc=s.substring(index, s.length());
rt.exec("Taskkill /PID" +sc+" /T /F");
}
JOptionPane.showMessageDialog(null, "Server Stopped");
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Something Went wrong with server");
}