// 设置保存上传文件的目录
String uploadDir = getServletContext().getRealPath("/") + "upload"; // 获得服务器的绝对路径
if(uploadDir == null) {
out.print("无法访问存储目录!");
return;
}
File fUploadDir = new File(uploadDir);
if(!fUploadDir.exists()) {
if(!fUploadDir.mkdir()) {
out.println("无法创建存储目录!");
return;
}
}
这段已经为你创建了这个目录 不需要手动去创建
String uploadDir = getServletContext().getRealPath("/") + "upload"; // 获得服务器的绝对路径
if(uploadDir == null) {
out.print("无法访问存储目录!");
return;
}
File fUploadDir = new File(uploadDir);
if(!fUploadDir.exists()) {
if(!fUploadDir.mkdir()) {
out.println("无法创建存储目录!");
return;
}
}
这段已经为你创建了这个目录 不需要手动去创建
解决方案 »
- 一个很菜的servlet问题,希望EE的高人给个问题解决方案
- struts2 文件动态下载问题
- 高手指点下 servlet抛出异常 javax.servlet.ServletException: Servlet execution threw an exception
- 帮忙分析一下
- 在线等!!请大家帮我看看这个程序 跟想象的结果不同啊 看哪里的问题啊
- 刚接触j2ee,问些幼稚的问题,关于动态生成组件的。
- 如何将动态参数传倒Action中去,100分! (在线等!!!)
- JB开发STRUTS遇到问题
- 在weblogic中建立连接池出现的问题,请相助
- Spring Task
- 要工作还是要生活
- 弹出确认框问题?
System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."),fileName.length()));
前面的路径用uploadDir 你创建保存文件夹的路径FileOutputStream fos = new FileOutputStream(uploadDir+File.separator +
System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."),fileName.length()));
如果存在指定的地方String uploadpath=“E:\\”;FileOutputStream fos = new FileOutputStream(uploadpath +
System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."),fileName.length()));
fos.write(*,0,*);//*号你自己改吧
如果存在指定的地方String uploadpath=“E:\\”; FileOutputStream fos = new FileOutputStream(uploadpath +
System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."),fileName.length()));
fos.write(*,0,*);//*号你自己改吧