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. }
  • 相关阅读:
    Windows 上 Redis 的安装
    SpringBoot项目application.yml 问题
    Gradle项目使用zxing在windows下报错:android:jar must specify an absolute path but is /${env.ANDROID_HOME}/…
    day23<AJAX>
    day22<文件上传>
    day21<过滤器>
    day20<监听器&国际化>
    day19<Service>
    day18<事务&连接池&DBUtils>
    day17<JDBC>
  • 原文地址:https://www.cnblogs.com/jackydalong/p/2483265.html
Copyright © 2011-2022 走看看