// 设置保存上传文件的目录
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;
}

这段已经为你创建了这个目录 不需要手动去创建

解决方案 »

  1.   

    FileOutPutStream实现文件字符流的输出!
      

  2.   

    FileOutputStream fos = new FileOutputStream(request.getRealPath("/") +
    System.currentTimeMillis() +
    fileName.substring(fileName.lastIndexOf("."),fileName.length())); 
    前面的路径用uploadDir 你创建保存文件夹的路径FileOutputStream fos = new FileOutputStream(uploadDir+File.separator +
    System.currentTimeMillis() +
    fileName.substring(fileName.lastIndexOf("."),fileName.length())); 
      

  3.   

    如果存入你程序所在目录中:String uploadpath=request.getRealPath("/")+"你想存的文件夹名称"
    如果存在指定的地方String uploadpath=“E:\\”;FileOutputStream fos = new FileOutputStream(uploadpath + 
    System.currentTimeMillis() + 
    fileName.substring(fileName.lastIndexOf("."),fileName.length())); 
    fos.write(*,0,*);//*号你自己改吧
      

  4.   

    如果存入你程序所在目录中:String uploadpath=request.getRealPath("/")+"你想存的文件夹名称" 
    如果存在指定的地方String uploadpath=“E:\\”; FileOutputStream fos = new FileOutputStream(uploadpath + 
    System.currentTimeMillis() + 
    fileName.substring(fileName.lastIndexOf("."),fileName.length())); 
    fos.write(*,0,*);//*号你自己改吧