首页 > 代码库 > 【Java代码片】判断操作系统等系统信息
【Java代码片】判断操作系统等系统信息
/** JVM vendor info. */ public static final String JVM_VENDOR = System.getProperty("java.vm.vendor"); public static final String JVM_VERSION = System.getProperty("java.vm.version"); public static final String JVM_NAME = System.getProperty("java.vm.name"); /** The value of <tt>System.getProperty("java.version")</tt>. **/ public static final String JAVA_VERSION = System.getProperty("java.version"); /** The value of <tt>System.getProperty("os.name")</tt>. **/ public static final String OS_NAME = System.getProperty("os.name"); /** True iff running on Linux. */ public static final boolean LINUX = OS_NAME.startsWith("Linux"); /** True iff running on Windows. */ public static final boolean WINDOWS = OS_NAME.startsWith("Windows"); /** True iff running on SunOS. */ public static final boolean SUN_OS = OS_NAME.startsWith("SunOS"); /** True iff running on Mac OS X */ public static final boolean MAC_OS_X = OS_NAME.startsWith("Mac OS X"); /** True iff running on FreeBSD */ public static final boolean FREE_BSD = OS_NAME.startsWith("FreeBSD"); public static final String OS_ARCH = System.getProperty("os.arch"); public static final String OS_VERSION = System.getProperty("os.version"); public static final String JAVA_VENDOR = System.getProperty("java.vendor");
以上代码摘自Lucene org.apache.lucene.util.Constants类
另外还可以用下面的方式:
private static String OS = System.getProperty("os.name").toLowerCase(); /** * 判断是否Windows * * @return */ public static boolean isWindows() { return OS.indexOf("win") >= 0; } public static boolean isMac() { return (OS.indexOf("mac") >= 0); } public static boolean isUnix() { return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0); } public static boolean isSolaris() { return (OS.indexOf("sunos") >= 0); }
以上代码参考:http://www.java-gaming.org/index.php?topic=14110.0
【Java代码片】判断操作系统等系统信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。