public void downLoad(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("audio/wav");
File file = new File(path);
String filename = file.getName();
String encodeString = null;
try {
filename = new String(filename.getBytes(response.getCharacterEncoding()), request.getCharacterEncoding());
encodeString = URLEncoder.encode(filename, "utf-8");
} catch (Exception e) {
logger.error(e, e);
}
response.setHeader("Content-dihttp://www.zhihu.com/people/cpjay
public void downLoad(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("audio/wav");
File file = new File(path);
String filename = file.getName();
String encodeString = null;
try {
filename = new String(filename.getBytes(response.getCharacterEncoding()), request.getCharacterEncoding());
encodeString = URLEncoder.encode(filename, "utf-8");
} catch (Exception e) {
logger.error(e, e);
}
response.setHeader("Content-dihttp://www.zhihu.com/people/cpjay
本文介绍了一个文件下载的方法实现,包括设置HTTP响应头以正确处理文件名的编码,支持浏览器直接下载指定路径下的文件。
4万+

被折叠的 条评论
为什么被折叠?



