Java调用DOS实现定时关机的实例
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:publicstaticvoidshutdown(){System.out.print("请输入多少分钟后关机:");Sc...
复制代码 代码如下:
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();
}
}