首页 > 编程语言 > 详细

java 获取 jar 目录 生成 logs 目录

时间:2016-10-10 13:43:37      阅读:142      评论:0      收藏: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");
        }
        
    }

 

java 获取 jar 目录 生成 logs 目录

原文:http://www.cnblogs.com/feelgood/p/5945285.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!