int count=0;          
// Initialization 
mySmartUpload.initialize(pageContext);  
// Upload  
mySmartUpload.upload();  
int iSize=mySmartUpload.getSize();
out.println("iSize:"+iSize); 
byte lst[]=new byte[iSize];
for(int i=0;i<iSize;i++)
{
lst[i]=mySmartUpload.getBinaryData(i);
}
out.println(lst);

解决方案 »

  1.   

    to: tolixiaohui(lxh) 
    计算文件大小?还是报错:This path does not exist (1135). 
      

  2.   

    你的路径不对
        ServletContext servletContext = getServletContext();
        mySmartUpload.getFiles().getFile(0).saveAs( servletContext.getRealPath("upload/") +"/"+ fileName);
      

  3.   

    在该文件所在的文件夹下创建目录/upload,以后就行了,注意:是tomcat/webapp/myproject/下,不是tomcat/webapp/下,
    更彻底一点的方法可以这样做:
    com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(0);
    if((myFile.isMissing()))
      throw new Exception("Error");
    myFile.saveAs("c:\\upload\\temp.txt");
    索性指定个物理地址
      

  4.   

    E:\soft\Tomcat 4.1\work\Standalone\localhost\yeshot\jspsmartupload\jsp\sample1_jsp.java:93: cannot resolve symbol
    symbol  : variable myUpload 
    location: class org.apache.jsp.sample1_jsp
    com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(0);
                                      ^
    1 errordjws() 的方法报错。找不到myUpload物理路径试过,不行。
      

  5.   

    以下是我寫的一個文件上傳程序﹐沒有問題﹐希望對你有用<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" errorPage="" %><%@ import="com.jspsmart.upload.*"%><%@ page import="java.util.Date"%><jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
    <%@ include  file = "header.inc" %><%
    Date date = new Date();
    String sYear = String.valueOf(date.getYear() + 1900);
    String sMonth = String.valueOf(date.getMonth() + 1);
    if(sMonth.length()<2)  sMonth = "0" + sMonth; 
    String sPath = sYear + sMonth;String sDestPath = "";
    String sAction = request.getParameter("medule");
    if(sAction.equals("attachment")){
    sDestPath = "G:\\Files\\" + sPath +"\\Attachments\\";
    }else{
    sDestPath = "G:\\Files\\" + sPath +"\\";
    }
    File d = new File(sDestPath);
    if(!d.exists()) d.mkdir();   // create a new directoryString sFilename = request.getParameter("filepath");
    if(sFilename != ""){mySmartUpload.initialize(pageContext);mySmartUpload.upload();
    // Select each file
    int count = 0;
    for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
    // Retreive the current file
    com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
    // Save it only if this file exists
    if (!myFile.isMissing()) {
    // sample with a physical path
    File f = new File(sDestPath,myFile.getFileName());
    if(f.exists()){
    %>
    <script>
    var msg = "文件已經存在﹗是否要替換﹖";
    if((confirm(msg))==false){
    window.close();
    }
    </script>
    <%
    }
     myFile.saveAs(sDestPath + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL); out.println("FileName = " + myFile.getFileName() + "<BR>");
    out.println("Size = " + myFile.getSize() + "<BR>");
    out.println("FileExt = " + myFile.getFileExt() + "<BR>");
    out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
    count ++;

    // Display the number of files which could be uploaded 
    out.println("<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>");
    // Display the number of files uploaded 
    out.println(count + " file(s) uploaded.");
    }
    }
    }
    %>
      

  6.   

    E:\soft\Tomcat 4.1\work\Standalone\localhost\yeshot\jspsmartupload\jsp\sample1_jsp.java:93: cannot resolve symbol
    symbol  : variable myUpload 
    location: class org.apache.jsp.sample1_jsp
    com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(0);
                                      ^
    1 errordjws() 的方法报错。找不到myUpload物理路径试过,不行。
    我贴的是我写的代码,你用的bean的id是mySmartUpload,将我的myUpload换成mySmartUpload就成了
      

  7.   

    在你的程序所在的文件夹下建立upload目录,不会不行的