這是我第一個Java程式,雖然之前學過Java,但沒怎么實際應用過
自動關機主要使用到兩個命令
// second為自定義秒數,為整數 shutdown -s -t second
// 取消自動關機 shutdown -a
以下是main函式
1 public static void main(String[] args) throws IOException { 2 // TODO Auto-generated method stub 3 // 關機 4 System.out.println("自動關機"); 5 System.out.println("輸入秒數設定自動關機:"); 6 @SuppressWarnings("resource") 7 Scanner input = new Scanner(System.in); 8 String x = input.nextLine(); 9 Runtime.getRuntime().exec("shutdown -s -t " + x); 10 System.out.println("將在"+x+"秒后自動關機"); 11 // 取消關機 12 // Runtime.getRuntime().exec("shutdown -a"); 13 // System.out.println("取消關機"); 14 }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/162016.html
標籤:Java
上一篇:你要的Netty常見面試題總結,我面試回來整理好了!
下一篇:NoSQL概述
