我思故我強

          java判斷操作系統(tǒng)

          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 李云澤 閱讀(2884) 評論(0)  編輯  收藏 所屬分類: Java代碼

          主站蜘蛛池模板: 无极县| 临邑县| 易门县| 安多县| 丽江市| 姜堰市| 岳阳市| 尉犁县| 太谷县| 永春县| 禹州市| 商洛市| 博客| 延吉市| 奇台县| 长岛县| 翁源县| 竹山县| 福建省| 隆昌县| 绥宁县| 葫芦岛市| 休宁县| 吕梁市| 文山县| 延吉市| 芮城县| 饶平县| 桐庐县| 腾冲县| 河津市| 黄陵县| 开鲁县| 城口县| 本溪| 临泉县| 利川市| 江陵县| 隆昌县| 崇州市| 大理市|