Hello Sir,
             I am working on J2EE application Server and on EJB and trying to Download a "Text File" from our application server..
             I am using the Following code for downloading,but the thing is that,no doubt it downloads the Text file properly,it takes
             a LONG time to do so....
 
  <code>
  public HttpServletResponse doDownloadFile(HttpServletRequest req,HttpServletResponse res)
  throws ServletException,IOException {  
  
   ServletOutputStream stream = null;  
   res.setContentType("application/binary");
  
   String fname1 = req.getParameter("BusinessId");
   String fname2 = req.getParameter("AccountUserId");
   String fname =fname1+"-"+fname2+".txt";
   res.setHeader("Content-Disposition","inline; filename=\""+fname+"\";");
 
   BufferedInputStream bif = null;  
   try {
   
    bif = new BufferedInputStream(new FileInputStream("E:/abcd/download/xyz/"+fname));   
    stream = res.getOutputStream();
    int data;
    while(( data = "bif.read())" != -1) {      
    stream.write(data);
    stream.flush();    
    }
    bif.close();
   stream.close();   
   return res;
   } catch(Exception e) {
    System.out.println("The Exception is :"+e);
   }   
   finally {
   if (stream != null)
   stream.close();
   return res;
   } 
   }//end of method
 
</Code>
 
    Can anybody tell me how do i improve the Performance of the Code,or something is wrong with the code...
    Any suggestions or code snippets will be greatly appreciated...
 
Thanks a million is advance.
Regards
Sam
 
            

Reply via email to