java.net.URL url =loader.getResource(clsPath); //从URL对象中获取路径信息 String realPath=url.getPath(); //去掉路径信息中的协议名"file:" intpos=realPath.indexOf("file:"); if(pos>-1) { realPath=realPath.substring(pos+5); } //去掉路径信息最后包含类文件信息的部分,得到类所在的路径 pos=...
获取Java程序运⾏的路径获取当前jar包的路径 最开始我是⽤能够这种⽅式来获取当前 jar 包的⽂件的:private static String LOCATION = [MainClass].class.getProtectionDomain().getCodeSource().getLocation().getFile();但是如果路径中包含中⽂,就会变成带“%xx%xx”格式的字符串。所以应该这样写才对:pr...
java.net.URL url =loader.getResource(clsPath); //从URL对象中获取路径信息 String realPath=url.getPath(); //去掉路径信息中的协议名"file:" intpos=realPath.indexOf("file:"); if(pos>-1) { realPath=realPath.substring(pos+5); } //去掉路径信息最后包含类文件信息的部分,得到类所在的路径 pos=...
String filePath = null; try { filePath = java.net.URLDecoder.decode(url.getPath(), "utf-8"); } catch (Exception e) { e.printStackTrace(); } if (filePath.endsWith(".jar")) filePath = filePath.substring(0, filePath.lastIndexOf("/") + 1); java.io.File file = new java.io...