Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Hani Ibrahim
Added: Aug 15, 2018 10:17 PM
Views: 3
Returns brief platform name (windows, mac, linux, noarch)
  1.     /**
  2.      * Detect platform (Windows, macOS, ...)
  3.      *
  4.      * @return platform name as short string: win, mac, linux, noarch. If
  5.      * platform cannot detected "noarch" is returned
  6.      */
  7.     static String getOS() {
  8.         String osname = System.getProperty("os.name");
  9.         if (osname != null && osname.toLowerCase().contains("mac")) {
  10.             return "mac";
  11.         }
  12.         if (osname != null && osname.toLowerCase().contains("windows")) {
  13.             return "win";
  14.         }
  15.         if (osname != null && osname.toLowerCase().contains("linux")) {
  16.             return "linux";
  17.         }
  18.         return "noarch";
  19.     }