参考:
public class shutdownSystem extends Thread{
//设置关机时与分
private static shutdownH=10
private static shutdownM=10
public void run(){
//获取当关时与分
int thisH=Calendar .HOUR_OF_DAY
int thisM=Calendar.MINUTE
if(shutdownH==thisH &&shutdownM==thisM){
try {
//关机
java.lang.Runtime.getRuntime().exec( "shutdown -s ")
} catch (java.io.IOException e) {
e.printStackTrace()
}finally{
try{
//间隔一分钟检查一次,确保能检查到关机时间
this.sleep(60000)
}chatch(Exception ex){}
}
}
}
}
public static void main(String [] args){try {
Runtime.getRuntime().exec("shutdown -s -t 1")
} catch (IOException e) {
}
}