日期:2014-05-17  浏览次数:20749 次

java 大文件上传????????????
我想在java中实现大文件的上传(大概500M),

自己写的上传小一点文件还行,大一点的就崩溃了!!!

有没有这方面的例子????

不胜感激!!!!!!!!!!!

------解决方案--------------------
设置好缓冲500M应该是能承受的喵~~``

不知道楼主怎么实现的...
------解决方案--------------------
500M不是个小数目,能上传也很慢把
------解决方案--------------------
这么大的文件,晕哦,客户端提交数据,肯定全部都会缓存到你的服务器上来,你服务器内存不够肯定死了撒,呵呵,这么大的文件用其他方式吧,边读边写。用web上传它是一并传上来的,你搞不定的。
------解决方案--------------------
用apache上传组件吧
------解决方案--------------------
我这有个例子,没写注释
Java code
package com.fuyou;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
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.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

public class Fileupload extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public Fileupload() {
        super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
        super.destroy(); // Just puts "destroy" string in log
        // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     * 
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request
     *            the request send by the client to the server
     * @param response
     *            the response send by the server to the client
     * @throws ServletException
     *             if an error occurred
     * @throws IOException
     *             if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out
                .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
        out.println("<HTML>");
        out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
        out.println("  <BODY>");
        out.print("    This is ");
        out.print(this.getClass());
        out.println(", using the GET method");
        out.println("  </BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }

    /**
     * The doPost method of the servlet. <br>
     * 
     * This method is called when a form has its tag value method equals to
     * post.
     * 
     * @param request
     *            the request send by the client to the server
     * @param response
     *            the response send by the server to the client
     * @throws ServletException
     *             if an error occurred
     * @throws IOException
     *             if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletRespo