Chinaunix首页 | 论坛 | 博客
  • 博客访问: 298690
  • 博文数量: 53
  • 博客积分: 1266
  • 博客等级: 少尉
  • 技术积分: 572
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-16 16:45
文章分类

全部博文(53)

文章存档

2012年(37)

2011年(16)

分类: Java

2011-07-24 14:36:05

// 获取绝对根路径

public static String getAbsoluteRootPath() {

        String rootPath = Thread.currentThread().getContextClassLoader()

                .getResource("").toString();

       

        String headStr = "file:/";

        if (rootPath.startsWith(headStr)) {

            rootPath = rootPath.substring(headStr.length());

        } else if (rootPath.startsWith("/")) {

            rootPath = rootPath.substring(1);

        }

       

        return rootPath;

    }

 

    // 获取绝对路径

    public static String getAbsolutePath(String relativePath) {

        return getAbsoluteRootPath() + relativePath;

    }

阅读(1752) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~