您的位置:首页 > 其它

WEB 获取项目部署根目录

2013-08-29 11:53 211 查看
URL url = Function.class.getResource("Function.class");

String temppath = url.toString();

int startIndex = temppath.indexOf("file:");

int index = temppath.indexOf("WEB-INF");

basePath = temppath.substring(startIndex + "file:".length() + 1, index);

// 如果是linux的操作系统,并且开始没有file分隔符的话,那么要加上

if (System.getProperty("os.name").indexOf("Linux") != -1) {

if (!basePath.startsWith(File.separator)) {

basePath = File.separator + basePath;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: