ormFile file = uploadForm.getFile();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        InputStream stream = file.getInputStream();
        OutputStream bos = new FileOutputStream("C:\111");
                    int bytesRead = 0;
                    byte[] buffer = new byte[8192];
                    while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                        bos.write(buffer, 0, bytesRead);
                    }
                    bos.close();
                    stream.close();

解决方案 »

  1.   

    http://www.jspsmart.com/用这里提供的免费类。
      

  2.   

    <%@ page contentType="text/html; charset=gb2312" buffer="1" autoFlush="true"%><%@ page import="com.jspsmart.upload.*" %><body><%
    try{
    SmartUpload upload = new SmartUpload();
    upload.initialize(pageContext);
    upload.upload();
    for (int i=0;i<upload.getFiles().getCount();i++){
    com.jspsmart.upload.File newFile = upload.getFiles().getFile(i);
    if (!newFile.isMissing()) {
    newFile.saveAs("d:/websrc/upload/newFileName" );//修改你的存储路径
    out.println("FieldName = " + newFile.getFieldName() + "<BR>");
    out.println("Size = " + newFile.getSize() + "<BR>");
    out.println("FileName = " + newFile.getFileName() + "<BR>");
    } }
    }catch(Exception e){
    out.println(e.toString());
    }
    %>
    </body>
      

  3.   

    <HTML><HEAD><TITLE>File Upload Test</TITLE></HEAD>
    <BODY BGCOLOR="WHITE">
    <FONT SIZE="2" FACE="Arial">
    <CENTER>
    <HR>
    <H1>File Upload Test</H1>
    <HR>
    </CENTER>
    <FORM METHOD="POST" ACTION="http://localhost:8080/test/servlet/fileup" ENCTYPE="multipart/form-data">
    FILE <INPUT TYPE=FILE NAME="dataFile"><BR>
    TEXT 1: <INPUT TYPE=TEXT NAME=text1><BR>
    <INPUT TYPE=SUBMIT>
    </FORM>
    </FONT>
    </BODY></HTML>
      

  4.   

    /**
    *上面的是jsp文件,upload.jsp
    *下面的是html文件
    */<HTML>
    <HEAD></HEAD>
    <BODY>
    <form name="form1" method="post" enctype="multipart/form-data" action="upload.jsp" >
    <input type="file" name="file" class="textbox" size="30">
    <input type=submit name=submit value="submit"></form>
    </BODY>
    </HTML>
      

  5.   

    http://www.csdn.net/develop/Read_Article.asp?Id=18987