[Java] Java检测程序运行的操作系统类型 →→→→→进入此内容的聊天室

来自 , 2020-09-22, 写在 Java, 查看 107 次.
URL http://www.code666.cn/view/4f5a9bf1
  1. /*
  2. Check which operating system the program is running.
  3. The program explains itself.
  4. */
  5.  
  6. public class OSValidator {
  7.     public static boolean isWindows() {
  8.         String os = System.getProperty("os.name").toLowerCase();
  9.         return (os.indexOf("win") >= 0);
  10.     }
  11.    
  12.     public static boolean isMac() {
  13.         String os = System.getProperty("os.name").toLowerCase();
  14.         return (os.indexOf("mac") >= 0);
  15.     }
  16.    
  17.     public static boolean isUnix() {
  18.         String os = System.getProperty("os.name").toLowerCase();
  19.         return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0);
  20.     }
  21.    
  22.     public static boolean isSolaris() {
  23.         String os = System.getProperty("os.name").toLowerCase();
  24.         return (os.indexOf("sunos") >= 0);
  25.     }
  26. }
  27. //java/5314

回复 "Java检测程序运行的操作系统类型"

这儿你可以回复上面这条便签

captcha