【史上最全】Java判断操作系统类型

来源:互联网 发布:丝绸之路大数据 编辑:程序博客网 时间:2024/06/06 01:02
try {String osName = System.getProperty("os.name");if (osName == null) {throw new IOException("os.name not found");}osName = osName.toLowerCase(Locale.ENGLISH);if (osName.indexOf("windows") != -1) {os = 1;} else if ((osName.indexOf("linux") != -1)|| (osName.indexOf("mpe/ix") != -1)|| (osName.indexOf("freebsd") != -1)|| (osName.indexOf("irix") != -1)|| (osName.indexOf("digital unix") != -1)|| (osName.indexOf("unix") != -1)|| (osName.indexOf("mac os x") != -1)) {os = 2;} else if ((osName.indexOf("sun os") != -1)|| (osName.indexOf("sunos") != -1)|| (osName.indexOf("solaris") != -1)) {os = 3;} else if ((osName.indexOf("hp-ux") != -1)|| (osName.indexOf("aix") != -1)) {os = 3;} else {os = 0;}} catch (Exception ex) {os = -1;}

0 0
原创粉丝点击