public static void main(String[] args) { String path = ClassName.class.getProtectionDomain().getCodeSource().getLocation().getPath(); try{ path = java.net.URLDecoder.decode(path, "UTF-8");//转换处理中文及空格 }catch (java.io.UnsupportedEncodingException e){ e.printStackTrace(); } File file = new File(path); if(file != null){ String jarPath = file.getParent(); System.out.println(jarPath); jarPath = jarPath.substring(0,jarPath.lastIndexOf(file.separator) + 1); System.out.println(jarPath+"logs"+file.separator+"test.log"); } }