destroy() 方法是 Java Process 類的一個方法。它是由 Process 類定義的抽象方法。此方法用於終止或簡單地終止進程。
用法
public abstract void destroy()
參數
NA
返回
此方法不返回值。
例子1
public class ProcessdestroyMethodExample1 {
public static void main(String[] args)
{
try{
//creating a new process
System.out.println("Creating a new process");
Process p1= Runtime.getRuntime().exec("notepad.exe");
p1.destroy();
System.out.println("Process destroyed");
}catch(Exception e)
{
System.out.println("Exception e");
}
}
}
輸出:
Creating a new process Process Destroyed
例子2
public class ProcessdestroyMethodExample2{
public static void main(String[] args) {
try{
System.out.println("creating a new process");
ProcessBuilder b2 = new ProcessBuilder("notepad.exe");
Process p2= b2.start();
System.out.println("waiting");
Thread.sleep(900);
p2.destroy();
System.out.println("process destroyed");
}
catch(Exception e){
System.out.println(e);
}
}
}
輸出:
creating a new process waiting process destroyed
相關用法
- Java Process waitFor()用法及代碼示例
- Java Process destroy()用法及代碼示例
- Java Process isAlive()用法及代碼示例
- Java Process getOutputStream()用法及代碼示例
- Java Process exitValue()用法及代碼示例
- Java Process getInputStream()用法及代碼示例
- Java Process getErrorStream()用法及代碼示例
- Java ProcessBuilder redirectErrorStream()用法及代碼示例
- Java ProcessBuilder environment()用法及代碼示例
- Java ProcessBuilder start()用法及代碼示例
- Java ProcessBuilder directory()用法及代碼示例
- Java Provider keySet()用法及代碼示例
- Java Properties propertyNames()用法及代碼示例
- Java Provider.Service getAttribute()用法及代碼示例
- Java Provider getName()用法及代碼示例
- Java Properties compute(Key, BiFunction)用法及代碼示例
- Java Provider keys()用法及代碼示例
- Java Properties containsKey(value)用法及代碼示例
- Java Properties computeIfAbsent(Key, Function)用法及代碼示例
- Java Provider.Service toString()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Process Destroy() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。