Java调用DOS实现定时关机的实例
程序员文章站
2023-12-01 13:48:35
复制代码 代码如下:public static void shutdown(){ &nbs...
复制代码 代码如下:
public static void shutdown(){
system.out.print("请输入多少分钟后关机:");
scanner scanner = new scanner(system.in);
int minute = scanner.nextint()*60;
runtime runtime = runtime.getruntime();
string shutdown = "shutdown -s -t "+minute;
try {
runtime.exec(shutdown);
} catch (ioexception e) {
e.printstacktrace();
}
}