String filename = request.getparameter ("filename");
Get the output stream that you want to output from the client
OutputStream outputstream = Response.getoutputstream ();
An array of bytes for the output file, sending 600 bytes to the output stream at a time
byte b[] = new byte[600];
The file to download
File Fileload=new file ("c://exportexecl/" +filename+ "");
The client side uses the dialog box to save the file
Response.AddHeader ("Content-disposition", "Attachment;filename="
+ java.net.URLEncoder.encode (filename, "UTF-8"));
MIME type of notification service file
Response.setcontenttype (Getservletcontext (). GetMimeType (filename));
Notice the length of the customer service file
Long filelength = Fileload.length ();
String length = string.valueof (filelength);
Response.setheader ("content_length", length);
Read the file and send it to the customer service side for download
FileInputStream InputStream = new FileInputStream (fileload);
int n = 0;
while ((N=inputstream.read (b))!=-1) {
Outputstream.write (B,0,n);
}
Clear Cache
if (fileload.exists ()) {
Fileload.delete ();
SYSTEM.OUT.PRINTLN ("The server cache has been cleared! ");
}
File Download Key code