admin 管理员组

文章数量: 887021

OSUtil类:

package com.yk.jettech.OSUtil;

/**
 * @see 获取操作系统名称
 * @author Hoperun
 * @date 
 *
 */
public class OSUtil {
    private static final boolean osIsMacOsX;
    private static final boolean osIsWindows;
    private static final boolean osIsWindowsXP;
    private static final boolean osIsWindows2003;
    private static final boolean osIsWindowsVista;
    private static final boolean osIsLinux;
    private static final boolean osIsWindowsWin7;
    private static final boolean osIsWindowsWin8;
    private static final boolean osIsWindowsWin10;

    static {
        String os = System.getProperty("os.name");
        if(os != null)
            os = os.toLowerCase();
        osIsMacOsX = "mac os x".equals(os);
        osIsWindows = os != null && os.indexOf("windows") != -1;
        osIsWindowsXP = "windows xp".equals(os);
        osIsWindows2003 = "windows 2003".equals(os);
        osIsWindowsVista = "windows vista".equals(os);
        osIsLinux = os != null && os.indexOf("linux") != -1;
        osIsWindowsWin7 = os != null && os.indexOf("windows 7") != -1;
        osIsWindowsWin8 = os != null && os.indexOf("windows 8") != -1;
        osIsWindowsWin10 = os != null && os.indexOf("windows 10") != -1;
    }
    public static boolean isMacOSX(){
        return osIsMacOsX;
    }
    public static boolean isWindows(){
        return osIsWindows;
    }
    public static boolean isWindowsXP(){
        return osIsWindowsXP;
    }
    public static boolean isWindows2003(){
        return osIsWindows2003;
    }
    public static boolean isWindowsVista(){
        return osIsWindowsVista;
    }
    public static boolean isLinux(){
        return osIsLinux;
    }
    public static boolean IsWindowsWin7(){
        return osIsWindowsWin7;
    }
    public static boolean IsWindowsWin8(){
        return osIsWindowsWin8;
    }
    public static boolean IsWindowsWin10(){
        return osIsWindowsWin10;
    }
}

Tste类:

package com.yk.jettech.OSUtil;

public class TestOS {
    public static String getVersion(){
        return "----------分割线---------";
    }
    public static void main(String[] args) {
        System.out.println(System.getProperty("os.name"));
        System.out.println(getVersion());
        System.out.println("当前系统为Mac系统:"+OSUtil.isMacOSX());
        System.out.println("当前系统为Linux系统:"+OSUtil.isLinux());
        System.out.println("当前系统为Windows系统:"+OSUtil.isWindows());
        System.out.println("当前系统为Windows2003系统:"+OSUtil.isWindows2003());
        System.out.println("当前系统为WindowsXP系统:"+OSUtil.isWindowsXP());
        /**
         * 注意:如果使用的1.6的jdk,那么对于win7和win8系统都显示的"Windows Vista"
         * 如果要正确判断win7还是win8系统,则需要使用jdk1.7及以上版本
         * Android系统需要稍微改动
         */
        System.out.println("当前系统为Windows7系统:"+OSUtil.IsWindowsWin7());
        System.out.println("当前系统为Windows8系统:"+OSUtil.IsWindowsWin8());
        System.out.println("当前系统为Windows10系统:"+OSUtil.IsWindowsWin10());
    }
}

本文标签: 系统 代码 java