设置一个程序,输入多少秒之后电脑自动关闭。
import java.io.IOException;
import java.util.Scanner;
public class Demo01 {
public static void main(String[] args) throws IOException {
// 自动关机程序
Scanner sc = new Scanner(System.in);
System.out.print("请输入多少秒之后自动关机:");
int time = sc.nextInt();
Runtime.getRuntime().exec("shutdown -s -t " + time);
}
}
取消自动关机关机程序:
import java.io.IOException;
import java.util.Scanner;
public class Demo01 {
public static void main(String[] args) throws IOException {
// 取消自动关机程序
Runtime.getRuntime().exec("shutdown -a");
}
}
导出 jar 包放到桌面上可以快捷执行,导出 jar 包这里就不再给出了。