首页  :: 新随笔  :: 管理

获取工程路径(jar和普通文件结构通用) -- java

Posted on 2011-09-28 22:22  季枫  阅读(267)  评论(0)    收藏  举报
    /**
     * 获取工程所在目录
     * 
@return
     * 
@throws UnsupportedEncodingException
     
*/
    private static String getProjectPath() throws UnsupportedEncodingException{
        URL url = UpdateHook.class.getProtectionDomain().getCodeSource().getLocation();
        String filePath = URLDecoder.decode(url.getPath(), "UTF-8");
        if(filePath.endsWith(".jar"))
            filePath = filePath.substring(0, filePath.lastIndexOf("/") + 1);
        return filePath;
    }
智读 | 成都会领科技有限公司官网 | 智读App下载 | 每天听本书的博客 | |