首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

判断现阶段操作系统是 windows 还是 linux

2012-07-08 
判断当前操作系统是 windows 还是 linux需要在windows 和 linux 上都能用。所以就需要自己在代码里面判断。

判断当前操作系统是 windows 还是 linux
需要在windows 和 linux 上都能用。
所以就需要自己在代码里面判断。
当前的操作系统是linux还是windows。
贴代码:

import java.net.URL;public class OS { public static final String CLASS_PATH; public static final boolean isLinux; static {  URL resource = OS.class.getResource("OS.class");  String classPath = resource.getPath();  String className = OS.class.getName().replace('.', '/') + ".class";  String classesPath = classPath.substring(0, classPath.indexOf(className));  System.out.println(classesPath);  if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1&& classesPath.startsWith("/")) {   classesPath = classesPath.substring(1);   isLinux = false;  } else {   isLinux = true;  }  CLASS_PATH = classesPath; }  public static void main(String arg[]){    System.out.println(OS.isLinux);  System.out.println(CLASS_PATH); }}

热点排行