通过 item.write(new File(filePath + fileName));直接写文件 不溢出 ,byte[] arg0=org.springframework.util.FileCopyUtils.copyToByteArray(item.getInputStream());
file.setFileEntity(arg0);存数据库 上传几个文件后就溢出,估计就是流没关闭,怎么能关闭流啊!!!

解决方案 »

  1.   

    怎么能关闭流啊!!!close()方法啊???
      

  2.   

    item 是 FileItemclose()方法 加了 也不好使
      

  3.   

    这是源码 
    try {
    request.setCharacterEncoding("UTF-8"); FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    // upload.setHeaderEncoding(request.getCharacterEncoding());
    System.out.println("request:" + request);
    List items = upload.parseRequest(request);
    Map fieldMap= new HashMap(); Iterator iter = items.iterator();
    while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next(); if (item.isFormField()) {/*

    fieldMap.put(item.getFieldName(), item.getString());

    } else {
    String fieldName = item.getFieldName();
    String fileName = item.getName();
    // boolean isInMemory = item.isInMemory();
    long sizeInBytes = item.getSize();
    if(sizeInBytes>this.getSizeMax()){
    throw new FileSizeMaxException();
    }
    IFile file=(IFile) this.getFileMgr().createNewPojo();
    byte[] arg0=org.springframework.util.FileCopyUtils.copyToByteArray(item.getInputStream());
    file.setFileEntity(arg0);
    file.setFileName(fileName);
    file.setFileSize((int)sizeInBytes);
    file.setFileType(item.getContentType());
    file.setSeque(System.currentTimeMillis());
    String id=this.getFileMgr().save((IRelatPojo)file, (String)fieldMap.get(super.MAIN_POJOID));
    item.getInputStream().close();//                  文件保存到硬盘 好用
    // String filePath = this.getServlet().getServletContext().getRealPath("/") + "uploadfile/" + "/";
    //  filePath = "D:/upload/";
    // File savePath = new File(filePath);
    // System.out.println(savePath.getAbsolutePath());
    // if (!savePath.exists()) {
    // savePath.mkdir();
    // }
    // item.write(new File(filePath + fileName)); }
    }
    } catch (Exception e) {
    e.printStackTrace();
    throw e;
    }