2

I need to download files from a server. based on situation I may need to download one or more than one file.

Currently I am able to download only one file. But can anyone help me out in downloading multiple files.

My Code:

<%ArrayList grep=(ArrayList<String>)request.getAttribute("consoleOutputForSFTP");
ArrayList filename=new ArrayList<String>();
%>

<br><%if(grep==null){

 %>Awaiting Response from Server...<%}else{ %>

<%for(int i=0;i<grep.size();i++){ %>
<%if(grep.toArray()[i].toString().contains(".edr.out")) {%>

<%String[] downloadFileName=grep.toArray()[i].toString().split("/");
for(int j=0;j<downloadFileName.length;j++){
    if(downloadFileName[j].contains(".edr.out")){
         filename.add(downloadFileName[j]);
    }%>


<%} %>

<%  
    String filepath = "D:/DownloadedFiles/";   
      response.setContentType("APPLICATION/OCTET-STREAM");   
      for(int l=0;l<filename.size();l++){
          response.setHeader("Content-Disposition","attachment; filename=\"" + filename.toArray()[l].toString() + "\"");   



      java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename.toArray()[l].toString());  

      int k;   
      while ((k=fileInputStream.read()) != -1) {  
        out.write(k);   
      }   
      fileInputStream.close();

      }
    %>

<%=grep.toArray()[i].toString() %><br>

<%



} %>

<%=grep.toArray()[i].toString() %><br>


<%} }%>

</body>
</html>
T Kanagaraj
  • 245
  • 5
  • 20

0 Answers0