我思故我強

          java判斷操作系統

          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));
          ??
          ??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);
          ?}
          }

          posted on 2008-02-01 10:13 李云澤 閱讀(2892) 評論(0)  編輯  收藏 所屬分類: Java代碼

          主站蜘蛛池模板: 德保县| 竹北市| 襄城县| 长治县| 茌平县| 安阳县| 昭觉县| 庆元县| 库车县| 东山县| 福海县| 吉林市| 岳阳市| 南华县| 稷山县| 大庆市| 桑植县| 新昌县| 黄平县| 托克逊县| 剑川县| 乐至县| 大足县| 泗水县| 怀宁县| 灵璧县| 繁峙县| 阜康市| 古浪县| 梧州市| 汤原县| 西贡区| 达州市| 滁州市| 霍城县| 吉木萨尔县| 桑日县| 蒲城县| 莲花县| 安化县| 荆州市|