File File =NewFile (path);//path is based on the log path and file name .String filename = File.getname ();//Get log file nameInputStream FIS =NewBufferedinputstream (NewFileInputStream (path));byte[] buffer =New byte[Fis.available ()];fis.read (buffer); Fis.close (); Response.reset () ;//first remove the space in the file name, and then convert the encoding format to utf-8, to ensure that there is no garbled, this file name is used in the browser's download box automatically display the filenameResponse.AddHeader ("Content-disposition", "attachment;filename=" +NewString (Filename.replaceall ("," "). GetBytes (" Utf-8 ")," Iso8859-1 ")); Response.AddHeader ("Content-length", "" "+file.length ()); OutputStream OS=NewBufferedoutputstream (Response.getoutputstream ()); Response.setcontenttype ("Application/octet-stream"); os.write (buffer);//Output FileOs.flush (); Os.close ();
struts2.0, you can use the public void DownloadFile () {} method, the return value type is void, and the direct write downloadfile.do can appear when you call the download prompt box
Javaweb Project implementation File download