This time to note the new download file method, before are InputStream and OutputStream, a little trouble, today in the project found in a method, and then to the spring website to see, on the whole of a most simple piece of code out, directly on the code ...
Fileutils is in the Commons-io package ...
@RequestMapping ("/t")
@ResponseBody
Public responseentity<byte[]> T () throws IOException {
file File = new file ("F:" + file.separator + "1.png"); You put the file path//New String ("Online consumption record". GetBytes ("GBK"), "iso-8859-1")
httpheaders headers = new Httpheaders ();//Set a head
headers.setcontentdispositionformdata ("Attachment", "1.png");//file properties, which is what the file is called
Headers.setcontenttype ( Mediatype.application_octet_stream);/content is byte stream return
new responseentity<byte[]> ( Fileutils.readfiletobytearray (file), headers, httpstatus.ok);//Start Download
}
OK, it is so simple, the speed of hemp, has not been tested ... Need to be compared