Home > Java > JavaBase > body text

Detailed explanation of the solution to garbled file names in Java downloads

Release: 2019-12-03 15:49:07
Original
1987 people have browsed it

Detailed explanation of the solution to garbled file names in Java downloads

How to download garbled file names in java: (Recommended: java video tutorial)

Each browser has different encoding, Firefox uses What is base64.ie and Google use url encoding:

So when we set the response header

Content-Type getServletContext().getMineType(filename);
Content-Disposition accachment;filename=编码后的filename
Copy after login

url encoding

name = URLEncoder.encode(filename, "UTF-8");
Copy after login

base64 Coding

/**
传入文件的名称,进行Base64编码@param fileName@return
*/
public String base64EncodeFileName(String fileName) {
BASE64Encoder base64Encoder = new BASE64Encoder();
try {
return "=?UTF-8?B?"new String(base64Encoder.encode(fileName
.getBytes("UTF-8"))) + "?=";
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
Copy after login

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Detailed explanation of the solution to garbled file names in Java downloads. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!