In this post, I will explain about a Java program to shutdown computer. This is a very basic program in Java programming language. If you are Java beginners or want to start learning Java programming language, then this program will help you to understand the basic Java programming.
Before executing this program I assume you have configured Java in your computer. Copy the below program and create a file “ShutdownComputer.java” and execute it to shut down your computer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import java.io.*; public class ShutdownComputer { public static void main(String args[]) throws IOException { Runtime runtime = Runtime.getRuntime(); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter No. of Seconds after which You want your Computer to Shutdown:"); long a=Long.parseLong(br.readLine()); Process proc = runtime.exec("shutdown -s -t " +a); System.exit(0); } } |
Liked this tutorial? Do Like & share with your friends 🙂
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Java program, java program to shutdown computer, Java programming, Java programs, Java programs with examples, shut down computer in java, shut down your computer using java