servlet得到webroot路径

//file:/F:/WorkSpace/Myeclipse_Workspace_1/.metadata/.me_tcat7/webapps/Hello/WEB-INF/classes/
String classessPath = this.getClass().getResource("/").toString();

//F:/WorkSpace/Myeclipse_Workspace_1/.metadata/.me_tcat7/webapps/Hello/WEB-INF/classes/
String classessRealPath = classessPath.replace("file:/", "");

String webRootPath = classessRealPath.replace("WEB-INF/classes/", "");

File file = new File(webRootPath + "lrc");
if (!file.exists()) {
    file.mkdirs();
}

System.out.println(file.getAbsolutePath());

你可能感兴趣的:(JavaEE)