Answers
public class shutdownSystem extends Thread{
//设置关机时与分
private static shutdownH=10;
private static shutdownM=10;
public void run(){
// 获取当关时与分
int thisH=Calendar .HOUROFDAY;
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){}
}
}
}
}
布莱克狗德
answered 13 years, 5 months ago