Shutting down a computer

jjnguy picture jjnguy · Aug 25, 2008 · Viewed 98.8k times · Source

Is there a way to shutdown a computer using a built-in Java method?

Answer

David McGraw picture David McGraw · Aug 25, 2008

Create your own function to execute an OS command through the command line?

For the sake of an example. But know where and why you'd want to use this as others note.

public static void main(String arg[]) throws IOException{
    Runtime runtime = Runtime.getRuntime();
    Process proc = runtime.exec("shutdown -s -t 0");
    System.exit(0);
}