Home  >  Forum  >  Core Java
Post New Query

java program to shutdown computer


joined on
March 22,2013
Asked on August 25,2015
I want to shutdown my PC through a java program. Can any one tell how may I do this?
joined on
October 12,2013
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;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PCShutdown {
public static void main(String[] args) throws IOException{
Runtime run = Runtime.getRuntime();
BufferedReader buffreader = new BufferedReader(new InputStreamReader(System.in));
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);
System.exit(0);
}

}

Write Answer








Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us