Shutting down windows operating system by Java

 public class Main  
 {  
   public static void main(String[] args) throws IOException  
   {  
     String shutdownCommand="";  
     String operatingSystem = System.getProperty("os.name");  
   
     if ("Linux".equals(operatingSystem) || "Mac OS X".equals(operatingSystem))  
     {  
       shutdownCommand = "shutdown -h now";  
     }  
     else if (operatingSystem.startWith("Window"))  
     {  
       shutdownCommand = "shutdown -s -t 0";  
     }  
       
     Runtime.getRuntime().exec(shutdownCommand);  
     System.exit(0);  
   }  
 }  
   

留言

這個網誌中的熱門文章

Disable ionic's sidemenu content drag to toggle menu

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser