Thursday, 1 September 2016

Download files using Servlet ~ gniithelp

String fileName = "db.zip";
res.setContentType("application/octet-stream");
res.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
OutputStream oStream = res.getOutputStream();
FileInputStream file=new FileInputStream("c:\\db.zip");

String sOutput ="Arunkumar";/*what ever be the information you want to download, should be specified here.*/
int i=0;
while((i=file.read())!=-1){
oStream.write(i);}
file.close();
oStream.close();

No comments:

Post a Comment