public class Path {
public static final String CLASS_PATH;
public static final boolean isLinux;
static{
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;
}else{
isLinux=true;
}
CLASS_PATH=classesPath;
}
}
判断是Linux系统还是Windows系统,得到classesPath
最新推荐文章于 2022-09-17 14:31:02 发布