获取相对路径 String path = getClass().getProtectionDomain().getCodeSource().getLocation()
.getPath();
虽然 String path = getClass().getProtectionDomain().getCodeSource().getLocation().toURI() .getPath();
可以解决乱码和中文问题,但是当没有空格和中文时,这句会异常,不推荐使用。
path = java.net.URLDecoder.decode(path, "utf-8");
这样做获得的路径就没问题了。
呵呵 此问题解决!
String path = String path = getClass().getProtectionDomain().getCodeSource().getLocation()
.getPath();
path = java.net.URLDecoder.decode(path, "utf-8");
联系客服