当我部署我的 web 应用程序时,我需要创建一个目录。该目录将包含所有用户的个人资料。
代码:
public class ImageBootstrapper {
public static void initialise(ServletContextEvent sce) {
boolean mkDir = new File(sce.getServletContext().getRealPath("webapps").replace('\\','/') + "/profilePictures").mkdir();
}
}
结果: 创建目录(“profilePictures”)失败..他使用的路径:C:/apache-tomcat-7.0.6/webapps/spring-1/webapps/profilePictures
我需要什么: 在此路径创建目录(“profilePictures”)-> C:/apache-tomcat-7.0.6/webapps/spring-1/profilePictures
spring-1 是应用程序上下文