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代码判断当前系统是什么系统 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1726657448h1007084.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论