Java下载文件,中文名乱码(attachment;filename=中文文件名)

2021/11/24 17:11:00

本文主要是介绍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"));


这篇关于Java下载文件,中文名乱码(attachment;filename=中文文件名)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程