Java下载在firefox下面名字乱码,丢失后缀名称

来源:互联网 发布:linux系统移植是干嘛的 编辑:程序博客网 时间:2024/05/18 22:44

今天测试代码,Java下载在firefox下面名字乱码,丢失后缀名称,后来发现由于名称中有空格,导致转化的时候乱码,只要名字把空格去掉就正常了

resp.setHeader(
                    "Content-Disposition",
                    "attachment;filename="
                            + new String((docAppfile.getFilename().replaceAll(" ", "").replaceAll(
                                " ", "")).getBytes("gb2312"), "ISO-8859-1") + "."
                            + docAppfile.getFiletype());

1 0