Java-程序运行后关闭计算机
可能重复:Java-程序运行后关闭计算机,java,logout,shutdown,system-shutdown,Java,Logout,Shutdown,System Shutdown,可能重复: 嗨 我有一个Java程序,可以运行20次,大约需要3个小时。在此之后,我希望我的计算机关闭,或者让我以用户身份注销。我可以直接从程序中执行此操作,即直接在for循环之后执行 for(int i=0; i<20; i++){ //APPLICATION CODE } //SHUTDOWN OR LOGGOF CODE for(int i=0;i作为示例,您可以运行如下系统命令: public static void main(String arg[]) throws IOE
嗨 我有一个Java程序,可以运行20次,大约需要3个小时。在此之后,我希望我的计算机关闭,或者让我以用户身份注销。我可以直接从程序中执行此操作,即直接在for循环之后执行
for(int i=0; i<20; i++){
//APPLICATION CODE
}
//SHUTDOWN OR LOGGOF CODE
for(int i=0;i作为示例,您可以运行如下系统命令:
public static void main(String arg[]) throws IOException{
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("shutdown -s -t 0");
System.exit(0);
}
public void shutDown() {
try {
Runtime
.getRuntime()
.exec(
"shutdown -s -t 120 -c \"Message telling shutdown has initiliazed. To stop the shutdown.\"");
} catch (final IOException e) {
e.printStackTrace();
}
}