(文件名、目录名或卷标语法不正确

时间:2021-12-29 18:31:59
D:\eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\web\newfiles1
java.io.FileNotFoundException: D:\eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\web\newfiles1\F:\gg.jpg (文件名、目录名或卷标语法不正确。)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:449)
at cn.itcast.servlet.ManageServlet.doPost(ManageServlet.java:63)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at cn.itcast.filter.EncoderFilter.doFilter(EncoderFilter.java:27)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:722)
大家帮忙解决一下谢谢
源代码:
package cn.itcast.servlet;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;

import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;




public class ManageServlet extends HttpServlet {
private static final long serialVersionUID = 1L;


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String title=request.getParameter("title");

String timelength=request.getParameter("timelength");

System.out.println("视频名称:"+title);
System.out.println("时长:"+timelength);

}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
boolean m= ServletFileUpload.isMultipartContent(request);
if(m){

try {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
@SuppressWarnings("unchecked")
List<FileItem> items=upload.parseRequest(request);
String dir=request.getSession().getServletContext().getRealPath("newfiles1");


File dirfile=new File(dir);
if(!dirfile.exists()){
dirfile.mkdirs();
System.out.println("创建");
}
for(FileItem item:items){
if (item.isFormField()) {//如果是文本类型参数
String name = item.getFieldName();
    String value = item.getString();
                        System.out.println(name+"="+value);
  
}else{//如果是文件类型参数

System.out.println(dir);
File savefile=new File(dir,item.getName());
item.write(savefile);
}

}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}else{
doGet(request, response);
}



}

}

1 个解决方案

#1


该回复于2012-12-08 10:06:37被管理员删除

#1


该回复于2012-12-08 10:06:37被管理员删除