六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 45|回复: 0

Java中判断操作系统

[复制链接]

升级  4.67%

15

主题

15

主题

15

主题

秀才

Rank: 2

积分
57
 楼主| 发表于 2013-1-15 02:49:10 | 显示全部楼层 |阅读模式
/** * java version "1.6.0_11" * Java(TM) SE Runtime Environment (build 1.6.0_11-b03) * Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing) */import java.net.*; class Path {public static void main(String[] args) {boolean isLinux = true; URL resource = Path.class.getResource("Path.class"); String classPath = resource.getPath(); String className = Path.class.getName().replace(".", "/") + ".class"; String classesPath = classPath.substring(0, classPath.indexOf(className)); if( System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1 && classesPath.startsWith("/") ){classesPath = classesPath.substring(1); isLinux = false;}System.out.println( isLinux ? "LINUX" : "WINDOWS" ); System.out.println( classesPath );}} 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表