我想在java中实现大文件的上传(大概500M),自己写的上传小一点文件还行,大一点的就崩溃了!!!有没有这方面的例子????不胜感激!!!!!!!!!!!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【LOVEYOULOVE】截止到2008-07-18 16:52:24的历史汇总数据(不包括此帖):
    发帖的总数量:20                       发帖的总分数:1030                     每贴平均分数:51                       
    回帖的总数量:61                       得分贴总数量:20                       回帖的得分率:32%                      
    结贴的总数量:20                       结贴的总分数:1030                     
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:100.00%                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    敬礼!
      

  2.   

    这么大的文件,晕哦,客户端提交数据,肯定全部都会缓存到你的服务器上来,你服务器内存不够肯定死了撒,呵呵,这么大的文件用其他方式吧,边读边写。用web上传它是一并传上来的,你搞不定的。
      

  3.   

    我这有个例子,没写注释
    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, HttpServletResponse response)
    throws ServletException, IOException {
        System.out.println("requestCo"+"=="+request.getContentType());
    response.setContentType("text/html;charset=gb2312");
    PrintWriter out = response.getWriter();
    // 设置保存的文件的目录
    String uploadDir = getServletContext().getRealPath("/upload");
    System.out.println(uploadDir);
    if (uploadDir == null) {
    out.println("无法访问存储目录!");
    return;
    } File fUploadDir = new File(uploadDir);
    if (!fUploadDir.exists()) {
    if(!fUploadDir.mkdir()){
    out.println("无法创建存储目录!");
    return;
    }
    }
    if (!ServletFileUpload.isMultipartContent(request)) {
    out.println("只能外理mul的类型的数据");
    return;
    }
     FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload  fu = new ServletFileUpload(factory);//关键类
    fu.setSizeMax(1024 * 1024 * 400);
    // FileItemFactory factory = new DiskFileItemFactory();
    DiskFileItemFactory s = new DiskFileItemFactory();//设置临时文件最大值,如果大于这个值,就建一临时文件
    s.setSizeThreshold(1024*1024);
    fu.setHeaderEncoding("gb2312");
    List fileItem = null;
    try {
    fileItem = fu.parseRequest(request);
    } catch (FileUploadException e) {
    out.println("解析出错了");
    e.printStackTrace(out);
    return;
    }


    Iterator i = fileItem.iterator();
    while (i.hasNext()) {
    FileItem fi = (FileItem) i.next();
    if (fi.isFormField()) {
    String content = fi.getString("gb2312");
    String fieldName = fi.getFieldName();
    System.out.println(fieldName+content);
    } else {
    String pathSrc = fi.getName();
    if (pathSrc.trim().equals("")) {
    continue;
    }
    int start = pathSrc.lastIndexOf("\\");
    String fileName = pathSrc.substring(start + 1);
    File pathDest = new File(uploadDir, fileName);
    try {
    fi.write(pathDest);
    String fieldName = fi.getFieldName();
    request.setAttribute(fileName, fileName);
    } catch (Exception e) {
    out.println("存储文件出现问题");
    e.printStackTrace(out);
    return;
    }finally{
    fi.delete();
    } }
    } } /**
     * Initialization of the servlet. <br>
     * 
     * @throws ServletException
     *             if an error occurs
     */
    public void init() throws ServletException {
    // Put your code here
    }}
      

  4.   

    smartUpload/ fileupload都可以的,他们都支持的
      

  5.   

    smartUpload或者fileupload插件都可以的smartUpload就是为了实现文件上传功能的
      

  6.   

    smartupload 上传 不难 可以到 100M 左右 
    太大了也不行
      

  7.   

    网上有一个Web大文件断点续传控件:http://www.cnblogs.com/xproer/archive/2012/02/17/2355440.html
    此控件支持100G文件的断点续传操作,提供了完善的开发文档,支持文件MD5验证,支持文件批量上传。
    文件MD5值计算进度:文件MD5值计算完毕服务器根据MD5检测是否存在相同文件续传文件从服务器加载文件列表文件上传中文件上传完毕上传文件夹与Discuz!X2整合-后台安装断点续传控件与Discuz!X2整合-后台启用断点续传控件与Discuz!X2整合-后台断点续传控件启用成功与Discuz!X2整合-前台发帖页面与Discuz!X2整合-上传
      

  8.   

    这个不错。本来之前我们公司一直使用的是Flash的上传控件,但是后来业务发展,公司系统中传的文件也越来越大,基本上都是500MB左右的。导致服务器总是挂,内存被撑爆。而且我们公司的员工如果在上传大文件,那电脑内存高的吓死人。后来技术部的人分析发现是Flash上传控件的问题,必须换掉。在网上搜了很久搜到这个控件,测试了很久发现体验不错,确实能够解决我们公司的业务问题,所以就直接用了。