标签:servlet res utf-8 coder bsp out pos down encoder
String root= ServletActionContext.getServletContext().getRealPath(File.separator).replace("\\", File.separator); String fileName = "download.text"; File file = new File(root + fileName); in = new FileInputStream(file); // 设置响应正文的MIME类型 response.setContentType("Content-Disposition;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;" + " filename=\""+ URLEncoder.encode(fileName, "UTF-8") + "\""); // 把本地文件发送给客户端 out = response.getOutputStream(); int byteRead = 0; byte[] buffer = new byte[512]; while ((byteRead = in.read(buffer)) != -1) { out.write(buffer, 0, byteRead); } in.close(); out.close();
标签:servlet res utf-8 coder bsp out pos down encoder
原文地址:http://www.cnblogs.com/kuiyeit/p/6693957.html