Hello All,
I am using the Code,as below, to Download a Text File from a particular
Directory on the Server to any where the user need to download it through the Dialouge box...
But what i Really want to achieve is that the user should not be asked for an Dialouge box, instead it
should Download the Text file directly to "Desktop"(By Default)...
Is there a way to do so...if yes can anybody help me out with the solution...
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("C:/ABCD/download/XYZ/"+fname));
stream = res.getOutputStream();
byte [] buf = new byte[20480];
int data;
while(( data = bif.read(buf,0,20480)) != -1) {
stream.write(buf, 0, data);
stream.flush();
}
bif.close();
stream.close();
return res;
} catch(Exception e) {
System.out.println("The Exception in MainServlet is :"+e);
}
finally {
if (stream != null)
stream.close();
return res;
}
}//end of method
I had already posted the same question on java forum,but did not get any response..So please help me out...
Thanks a million in advance,
Regards
Sam