zoukankan      html  css  js  c++  java
  • 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. }
  • 相关阅读:
    【leetcode】71. Simplify Path
    【leetcode】891. Sum of Subsequence Widths
    【leetcode】68. Text Justification
    【leetcode】84. Largest Rectangle in Histogram
    【leetcode】726. Number of Atoms
    【leetcode】429. N-ary Tree Level Order Traversal
    【leetcode】436. Find Right Interval
    【leetcode】778. Swim in Rising Water
    BEC listen and translation exercise 9
    BEC listen and translation exercise 8
  • 原文地址:https://www.cnblogs.com/jackydalong/p/2483265.html
Copyright © 2011-2022 走看看