public static void-down (httpservletrequest request,
Httpservletresponseresponse) throws Exception {
String name= "aaa.*";//File name
String Uploadpath =uploadfilehelper.getrepositorypath () + "//";//File source
Stringfilepath = name;
String fileName = name;
if (Request.getheader ("User-agent"). toLowerCase (). IndexOf ("Firefox") > 0) {
FileName =new String (filename.getbytes ("UTF-8"), "iso8859-1");//firefox browser
}else {
if (Request.getheader ("User-agent"). toUpperCase (). IndexOf ("MSIE") > 0) {
filename = urlencoder.encode (filename, "UTF-8");//ie browser
}
}
Response.setcontenttype ("Text/plain");
Response.setheader ("Location", fileName);
Response.reset ();
Response.setheader ("Cache-control", "max-age=0");
Response.setheader ("Content-disposition", "attachment; filename=" + filename);
Bufferedinputstream bis = null;
Bufferedoutputstream Bos =null;
OutputStream fos = null;
InputStream FIS = null;
FilePath = Uploadpath +filepath;
FIS = Newfileinputstream (FilePath);
bis = new Bufferedinputstream (FIS);
FOS = Response.getoutputstream ();
BOS = new Bufferedoutputstream (FOS);
int bytesread = 0;
byte[] buffer = new BYTE[5 * 1024];
while ((bytesread = bis.read (buffer))! =-1) {
Bos.write (buffer, 0, bytesread);//Send file to Client
}
Bos.close ();
Bis.close ();
Fos.close ();
Fis.close ();
}
Java download file feature code example