public void preparePath(ServletContext context) { SimpleDateFormat sdf = new SimpleDateFormat("/yyyy/MM/dd/"); String basePath = context.getRealPath("/WEB-INF/weibo_files"); String subPath = sdf.format(new Date()); path = basePath + subPath + UUID.randomUUID().toString(); // avoids same // name // directory // if not exists then create it File dir = new File(path); if (!dir.exists()) { dir.mkdirs(); } // copy style files into it URL tamplateUrl = this.getClass().getResource("/templates/style"); try { FileUtils.copyFile(new File(tamplateUrl.toURI()), dir); } catch (URISyntaxException e) { LOG.error(e.getMessage()); } catch (IOException e) { LOG.error("occurred a errer when copy style files " + e); } }