Java下載文件,中文名亂碼(attachment;filename=中文文件名)


發現搜到的全部一樣的方案 new String(fileName.getBytes(), "ISO8859-1")

貼一個不一樣的解決方案

使用URLEncoder.encode

1
String attachName =  "這是中文名稱文件.txt" //<a href="https://www.cnblogs.com/tomcatandjerry/p/11541871.html">https://www.cnblogs.com/tomcatandjerry/p/11541871.html</a>
1
2
3
response.setCharacterEncoding( "utf-8" );
response.setContentType( "application/octet-stream" );
response.setHeader( "Content-Disposition" "attachment;filename="  + URLEncoder.encode(attachName,  "UTF-8" ));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM