downLoad
Posted Java ..
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了downLoad相关的知识,希望对你有一定的参考价值。
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();
以上是关于downLoad的主要内容,如果未能解决你的问题,请参考以下文章