1 4 package com.tc.util.runtime; 5 6 import java.io.File ; 7 8 13 public class Os { 14 15 private Os() { 16 } 18 19 public static String getOsName() { 20 return System.getProperty("os.name", "unknown"); 21 } 22 23 public static String platform() { 24 String osname = System.getProperty("os.name", "generic").toLowerCase(); 25 if (osname.startsWith("windows")) { 26 return "win32"; 27 } 28 else if (osname.startsWith("linux")) { 29 return "linux"; 30 } 31 else if (osname.startsWith("sunos")) { 32 return "solaris"; 33 } 34 else if (osname.startsWith("mac")) { 35 return "mac"; 36 } 37 else return "generic"; 38 } 39 40 public static boolean isWindows() { 41 return (getOsName().toLowerCase().indexOf("windows") >= 0); 42 } 43 44 public static boolean isLinux() { 45 return getOsName().toLowerCase().indexOf("linux") >= 0; 46 } 47 48 public static boolean isUnix() { 49 final String os = getOsName().toLowerCase(); 50 51 if ((os.indexOf("sunos") >= 0) || (os.indexOf("linux") >= 0)) { return true; } 53 54 if ((os.indexOf("mac") >= 0) && (System.getProperty("os.version", "").startsWith("10."))) { return true; } 55 56 return false; 57 } 58 59 public static boolean isMac() { 60 final String os = getOsName().toLowerCase(); 61 return os.startsWith("mac"); 62 } 63 64 public static boolean isSolaris() { 65 final String os = getOsName().toLowerCase(); 66 return os.indexOf("sunos") >= 0; 67 } 68 69 public static String findWindowsSystemRoot() { 70 if (!isWindows()) { return null; } 71 72 83 final char begin = 'c'; 85 final char end = 'z'; 86 87 for (char drive = begin; drive < end; drive++) { 88 File root = new File (drive + ":\\WINDOWS"); 89 if (root.exists() && root.isDirectory()) { return root.getAbsolutePath().toString(); } 90 91 root = new File (drive + ":\\WINNT"); 92 if (root.exists() && root.isDirectory()) { return root.getAbsolutePath().toString(); } 93 } 94 95 return null; 96 } 97 98 } 99 100 102 | Popular Tags |