2014-02-16 55 views
0

我有一個上傳文件的應用程序。我需要將此文件傳遞到另一個程序,但爲此我只需要文件名。有沒有簡單的代碼,只使用Java或servlet過程?使用servlet在eclipse中獲取上傳文件名

while (files.hasMoreElements()) 
{ 
     name = (String)files.nextElement(); 
     type = multipartRequest.getContentType(name); 
     filename = multipartRequest.getFilesystemName(name); 
     originalFilename = multipartRequest.getOriginalFileName(name); 

     //extract the file extension - this can be use to reject a 
     //undesired file extension      
     extension1 = filename.substring 
      (filename.length() - 4, filename.length()); 
     extension2 = originalFilename.substring 
      (originalFilename.length() - 4, originalFilename.length()); 

     //return a File object for the specified uploaded file 
     File currentFile = multipartRequest.getFile(name); 
     //InputStream inputStream = new BufferedInputStream 
      (new FileInputStream(currentFile)); 
     if(currentFile == null) { 
      out.println("There is no file selected!"); 
      return; 
     } 

回答