0

当我部署我的 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 是应用程序上下文

4

2 回答 2

0

代替

"/profilePictures"

"/../profilePictures"
于 2011-02-10T09:29:43.430 回答
0

你可以简单地这样做:

boolean mkDir = new File(
    sce.getServletContext().getRealPath("/profilePictures")).mkdir(); 
于 2011-02-10T09:40:31.113 回答