关于判断操作系统类型的java代码 How to detect OS in Java – System.getProperty(“os.name”)
2011-08-24 14:40
501 查看
How to detect OS in Java – System.getProperty(“os.name”)
Here is a handy Java class that use System.getProperty(“os.name”) to detect which type of operating system (OS) we are using now.
Here is a handy Java class that use System.getProperty(“os.name”) to detect which type of operating system (OS) we are using now.
public class OSValidator{ public static void main(String[] args) { if(isWindows()){ System.out.println("This is Windows"); }else if(isMac()){ System.out.println("This is Mac"); }else if(isUnix()){ System.out.println("This is Unix or Linux"); }else{ System.out.println("Your OS is not support!!"); } } public static boolean isWindows(){ String os = System.getProperty("os.name").toLowerCase(); //windows return (os.indexOf( "win" ) >= 0); } public static boolean isMac(){ String os = System.getProperty("os.name").toLowerCase(); //Mac return (os.indexOf( "mac" ) >= 0); } public static boolean isUnix(){ String os = System.getProperty("os.name").toLowerCase(); //linux or unix return (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0); } }
相关文章推荐
- How to Disable System Integrity Protection (rootless) in Mac OS X
- Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.init
- How to set the JAVA_HOME variable in Mac OS X – Snow Leopard
- How to get browser name, version and operating system detail in selenium 2(Web driver)
- How to check for and disable Java in OS X
- How to Disable System Integrity Protection (rootless) in OS X El Capitan
- How to make a Dialogue System in Unity
- How to Hide Folders in Mac OS X
- How to get a path to a resource in a Java JAR file
- How to implement a singleton class in Symbian OS
- java中获取操作系统参数的函数 System.getProperty(String key)
- How to get a high quality system in the developing process?
- How to invoke Java web service in ASP.net using C#
- 关于打开Eclipse时出现eclipse failed to create the java virtual machine与locking is not possible in the directory问题的解决
- How To Write In Sharepoint Log File 怎么对自定义的MOSS代码写日志
- How to install OS X Mountain Lion in Virtualbox with iAtkos
- mybatis 基本类型的if条件判断问题 There is no getter for property named 'xxx' in 'class Java.lang.Integer'
- How to read the Linux system name?
- How to collect the full path name of the files in ASM diskgroups (文档 ID 888943.1)
- how to increase an regular array length in java?