在 util 类下方结帐以进行操作系统验证。
使用系统属性:由于这个问题,这种方法可能会失败。请参阅Java 的 Windows 10 的“os.name”?
/**
* The Class OSValidator.
*/
public final class OSValidator {
/** The Constant OS. */
public static final String OS = System.getProperty("os.name").toLowerCase();
/**
* Checks if is windows 7.
*
* @return true, if is windows 7
*/
public static final boolean isWindows7() {
return (OS.indexOf("windows 7") >= 0);
}
/**
* Checks if is windows 10.
*
* @return true, if is windows 10
*/
public static final boolean isWindows10() {
return (OS.indexOf("windows 10") >= 0);
}
/**
* Checks if is mac.
*
* @return true, if is mac
*/
public static final boolean isMac() {
return (OS.indexOf("mac") >= 0);
}
}
使用 SystemUtils – Apache Commons Lang
public String getOperatingSystemSystemUtils() {
String os = SystemUtils.OS_NAME;
// System.out.println("Using SystemUtils: " + os);
return os;
}