Home > Back-end >  Download a file with a FileInputStream method in Chinese name can't display
Download a file with a FileInputStream method in Chinese name can't display

Time:09-26

Download content no problem, it is the original document, but download the document name of the Chinese part cannot display
Document name: script juben docx
Download created file name is


The background of the controller code
@ Controller
Public class DownLoadController {
The @autowired
FilesService FilesService;
@ RequestMapping (value="https://bbs.csdn.net/download")
Public String download (it request, HttpServletResponse response) throws IOException, ServletException {

Files Files=filesService. GetFilesById (request. The getParameter (" id "));
String filePath=files. GetFile ();
String path=SysModel. Get (" uploadRoot "). The toString () + filePath.
The File f=new File (path);
System. The out. Println (f.g etName ());//the output is the full name "script juben. Docx
"//read the download
FileInputStream in=new FileInputStream (f);
The response. SetHeader (" the Content - the disposition ", "legislation; Filename="+ f.g etName ());
The response. SetContentLength ((int) f.l ength ());
ServletOutputStream out=response. GetOutputStream ();
Byte [] b=new byte [1024].
int i=0;
While ((I=in the read (b)) & gt; 0 {
Out. Write (b, 0, I);
}
In the close ();
out.close();
return null;
}
}

I want to download the document name the same as the original name

CodePudding user response:

Should be the problem of coding, you should try the files are all letters can be according to the name, if is the problem of coding suggested you can check to see how to set the input stream encoding utf8
  • Related