- package com.evenle;
- import java.io.IOException;
- import java.util.Scanner;
- public class Shutdown {
- public static void main(String[] args) {
- System.out.println("输入多少分钟后关机:");
- Scanner sc = new Scanner(System.in);
- int s = sc.nextInt();
- s *= 60;
- Runtime rt = Runtime.getRuntime();
- String cmddir = "cmd /c shutdown -s -t "+s;
- try {
- rt.exec(cmddir);
- System.out.println("电脑将在"+s/60+"分钟后关闭");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1807201410028.html
来源: http://www.codesnippet.cn/detail/1807201410028.html