1.springmvc文件下载(原文地址:http://www.imooc.com/article/2760)
@Controller
@RequestMapping("/file/operate/")
public class FileOperate {
@RequestMapping("download")
public ResponseEntity<byte[]> download() throws IOException {
String fileName = "中文-demo.txt";
File file = new File("E:\\images\\中文-demo.txt");
String dfileName = new String(fileName.getBytes("gb2312"), "iso8859-1");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", dfileName);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
}
}