获取当前类运行的绝对路径

String currentClassPath = RandomCheckCode.class.getResource(File.separator).toString();
int beginIndex = currentClassPath.indexOf("/", 0)+1;
int endIndex = currentClassPath.lastIndexOf("/")+1;
                String OS = System.getProperty("os.name").toLowerCase();
if(OS.indexOf("win")!=-1)
beginIndex+=1;
System.out.println("path: "+ currentClassPath.substring(beginIndex, endIndex));

你可能感兴趣的:(OS)