java 获取 jar 目录 生成 logs 目录
2016-10-10 12:11 【戈多】 阅读(416) 评论(0) 编辑 收藏 举报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"); } }