Java 判断 OS 类型

    1. public class OSValidator{  
    2.    
    3.     public static void main(String[] args)  
    4.     {  
    5.         if(isWindows()){  
    6.             System.out.println("This is Windows");  
    7.         }else if(isMac()){  
    8.             System.out.println("This is Mac");  
    9.         }else if(isUnix()){  
    10.             System.out.println("This is Unix or Linux");  
    11.         }else{  
    12.             System.out.println("Your OS is not support!!");  
    13.         }  
    14.     }  
    15.    
    16.     public static boolean isWindows(){  
    17.    
    18.         String os = System.getProperty("os.name").toLowerCase();  
    19.         //windows  
    20.         return (os.indexOf( "win" ) >= 0);   
    21.    
    22.     }  
    23.    
    24.     public static boolean isMac(){  
    25.    
    26.         String os = System.getProperty("os.name").toLowerCase();  
    27.         //Mac  
    28.         return (os.indexOf( "mac" ) >= 0);   
    29.    
    30.     }  
    31.    
    32.     public static boolean isUnix(){  
    33.    
    34.         String os = System.getProperty("os.name").toLowerCase();  
    35.         //linux or unix  
    36.         return (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0);  
    37.    
    38.     }  
    39. }
原文地址:https://www.cnblogs.com/jackydalong/p/2483265.html