下載的內容沒有問題,是原檔案。但下載下來的檔案名稱中文部分無法顯示
檔案名稱:劇本juben.docx
下載創建的檔案名字是這樣的

后臺控制器的代碼
@Controller
public class DownLoadController {
@Autowired
FilesService filesService;
@RequestMapping(value="https://bbs.csdn.net/download")
public String download(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
Files files = filesService.getFilesById(request.getParameter("id"));
String filePath=files.getFile();
String path=SysModel.get("uploadRoot").toString()+filePath;
File f=new File(path);
System.out.println(f.getName());//這句話輸出的是完整名稱“劇本juben.docx”
//讀取下載
FileInputStream in=new FileInputStream(f);
response.setHeader("Content-disposition","attachment;filename="+f.getName());
response.setContentLength((int) f.length());
ServletOutputStream out=response.getOutputStream();
byte[] b=new byte[1024];
int i=0;
while((i=in.read(b))>0){
out.write(b, 0, i);
}
in.close();
out.close();
return null;
}
}
我想下載下來的檔案名稱跟原名稱一樣可以嗎
uj5u.com熱心網友回復:
應該是編碼的問題,你試試檔案全部是字母應該就可以按原名了吧,如果是編碼的問題建議你可以查查看怎么給輸入流設定編碼為utf8轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/78919.html
標籤:Web 開發
