java program to shutdown computer

Asked on August 25, 2015
I want to shutdown my PC through a java program. Can any one tell how may I do this?

Replied on August 25, 2015
There are many ways to send a shutdown signal to the OS to shutdown PC in java. See the below code(java code) that send a signal of shutdown to OS.

package javaCodeTesting;


public class PCShutdown {
public static void main(String[] args) throws IOException{
Runtime run = Runtime.getRuntime();
BufferedReader buffreader = new BufferedReader(new InputStreamReader(;
System.out.println("Enter the no. of seconds after which you want your computer to shutdown: ");
long a = Long.parseLong(buffreader.readLine());
Process pro = run.exec("shutdown -s -t " + a);


Write Answer

©2024 | Privacy Policy | Contact Us