The Runtime.getRuntime() method returns the singleton instance of Runtime class.
How to shutdown system in Java
You can use shutdown -s command to shutdown system. For windows OS, you need to provide full path of shutdown command e.g. c:\\Windows\\System32\\shutdown.Here you can use -s switch to shutdown system, -r switch to restart system and -t switch to specify time delay.
public class Runtime2{
public static void main(String args[])throws Exception{
Runtime.getRuntime().exec("shutdown -s -t 0");
}
}
How to shutdown windows system in Java
public class Runtime2{
public static void main(String args[])throws Exception{
Runtime.getRuntime().exec("c:\\Windows\\System32\\shutdown -s -t 0");
}
}
How to restart system in Java
public class Runtime3{
public static void main(String args[])throws Exception{
Runtime.getRuntime().exec("shutdown -r -t 0");
}
}
@reference_1_javatpoint.com
Java Runtime class
No comments:
Post a Comment