Лучшее решение для меня:
String path = Test.class.getProtectionDomain().getCodeSource().getLocation().getPath(); String decodedPath = URLDecoder.decode(path, "UTF-8");
Это должно решить проблему с пробелами и специальными символами.