/**
* 传文件到web页面,编码为UTF-8
*
* @param response
* @param fileFullPath
* @param response
* @throws IOException
*/
public void getFileContent(String fileFullPath, HttpServletResponse response) throws IOException {
String[] split = fileFullPath.split("\\\\");
if (split.length < 2) {
split = fileFullPath.split("/");
}
response.setCharacterEncoding("UTF-8");
// attachment是以附件的形式下载,inline是浏览器打开
response.setHeader("Content-Disposition", "inline;filename=" + split[split.length - 1] + ".txt");
response.setContentType("text/plain");
// 把二进制流放入到响应体中
ServletOutputStream os = response.getOutputStream();
File file = new File(fileFullPath);
byte[] bytes = FileUtils.readFileToByteArray(file);
os.write(bytes);
os.flush();
os.close();
}
页面中文可能会乱码,待处理