看看这个贴子,有相关的讨论。希望能解决你的问题
http://community.csdn.net/Expert/topic/3896/3896720.xml?temp=.2206232

解决方案 »

  1.   

    我用的是sturts的org.apache.struts.upload.FormFile
    jsp页:
    <html:form action"" method="post" styleId="" enctype="multipart/form-data">
    <html:file property="file" />
    Action:
    上传:
     String filePath = servlet.getServletContext().getRealPath("/upload");
            File uploadDir = new File(filePath);
            //Creat upload folder
            if (!uploadDir.isDirectory()) {
              uploadDir.mkdir();
            }        FormFile file = mActionForm.getFile();
            //Check File Size
            if (file.getFileSize() > 10 * 1024 * 1024) {
              throw new Exception("61006");
            }        if (file == null) {
              return actionMapping.findForward("page_showFileObjectUpload");
            }
            String fName = file.getFileName();        long size = file.getFileSize();
                   //Upload File
            InputStream streamIn = file.getInputStream();
            OutputStream streamOut = new FileOutputStream(destFileName + "/" +
              file.getFileName());
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            while ( (bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {
              streamOut.write(buffer, 0, bytesRead);
            }
            streamOut.close();
            streamIn.close();下载:
     String tempPath = servlet.getServletContext().getRealPath("/upload");        //Creat a GUId
            String GUId = new ForGuid().toString();
            String GUIdPath;
            if (tempPath.endsWith(eConst.STR_DELIMITER_BACKLASH)) {
              GUIdPath = tempPath + GUId;
            }
            else {
              GUIdPath = tempPath + "/" + GUId;
            }        //Download Attachment To Temp Directory
            proId = meSession.geteFile().download(id, GUIdPath, session.getAttribute("kGPassword").toString());        //Check Process Is Whether Finish
            checkprocess(proId);        //Decompression And Get File Path
            String strArray[] = getFilePath(GUIdPath);
            String fPath = strArray[0];
            String fName = strArray[1];        String fileName = fName;        InputStream inStream = new FileInputStream(fPath);        response.reset();
            response.setContentType("application/octet-stream; charset=GBK");
            response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");        byte[] b = new byte[50];
            int len;
            while ( (len = inStream.read(b)) > 0) {
              response.getOutputStream().write(b, 0, len);
            }
            response.getOutputStream().close();
            inStream.close();我得这个程序还有压缩和解压缩
    你根据自己的改改吧