您的位置:首页 > 运维架构 > Tomcat

web项目中将上传的文件保存到服务器的某个文件夹,保证clean tomcat时不会被清理掉

2016-06-20 11:05 435 查看

String testPath = request.getSession().getServletContext().getRealPath("");//tomcat下

  File directory = new File(testPath);//设定为当前文件夹

  File file = new File(directory.getParentFile().toString()).getParentFile();

  testPath = file.toString();

  testPath = testPath+"/briefing/Template/"+fileUrl.getOriginalFilename();

  File fileIsIsts = new File(testPath);

  if (!fileIsIsts.getParentFile().exists())

   fileIsIsts.getParentFile().mkdirs();

  if (!fileIsIsts.getParentFile().getParentFile().exists())

   fileIsIsts.getParentFile().getParentFile().mkdirs();

  fileUrl.transferTo(new File(testPath));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息