[background] requirements require that the exported user information Excel table file be downloaded from the server to the user locally
[code]
/**
* /
* @param request
* @param response
* @return
* @throws FTPConnectionClosedException
* @throws IOException
*/
public File downloadExcel (HttpServletRequest request, HttpServletResponse response)
throws FTPConnectionClosedException, IOException {
File file = new File(zipPath);
FileOutputStream fos = new FileOutputStream(file);
ZipUtils.toZip(path, fos, true);
//1.
String realPath = zipPath;
//2.
String fileName = realPath.substring(realPath.lastIndexOf(File.separator)+1);
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("multipart/form-data");
//3.content-disposition
response.addHeader("Content-Disposition","attachment;filename=" + new String(fileName.getBytes(),"utf-8"));
//
InputStream in = new FileInputStream(realPath);
int len = 0;
byte[] buffer = new byte[1024];
OutputStream out = response.getOutputStream();
while ((len = in.read(buffer)) > 0) {
//
out.write(buffer,0,len);
}
in.close();
return file;
}
[question] how to convert garbled code into normal Chinese?