NutzCN Logo
问答 火狐下载文件中文名是乱码,谷歌没问题,大家遇到过没
发布于 2534天前 作者 qq_4a89c7c9 1612 次浏览 复制 上一个帖子 下一个帖子
标签:

火狐下载文件中文名是乱码,谷歌没问题,大家遇到过没,求教

4 回复

怎么写的?

OutputStream out = null;
		InputStream in = null;
		try {
			// 获得文件名
			String filename = URLEncoder.encode(file.getName(), "UTF-8");
			// 定义输出类型(下载)
			response.setContentType("application/force-download");
			response.setHeader("Location", filename);
			// 定义输出文件头
			response.setHeader("Content-Disposition", "attachment;filename="
					+ filename);
			out = response.getOutputStream();
			in = new FileInputStream(file.getPath());
			byte[] buffer = new byte[1024];
			int i = -1;
			while ((i = in.read(buffer)) != -1) {
				out.write(buffer, 0, i);
			}
		}catch(Exception e) {
			if(in != null){
				in.close();
			if(out!=null)
				out.close();
			}
		}finally {
			if(in != null){
				in.close();
			if(out!=null)
				out.close();
			}
		}

试试raw吧

@Ok("raw")



return file;

filename转码试试

添加回复
请先登陆
回到顶部