码迷,mamicode.com
首页 > 编程语言 > 详细

java 获取 jar 目录 生成 logs 目录

时间:2016-10-10 13:45:36      阅读:125      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!