txt格式下载
public Object downloadPackage( Long id,HttpServletResponse response) throws Exception {
if (null != id && id > 0) {
CpNumberPackage numPack = this.cpNumberPackageService.findOne(id)
if (numPack != null && numPack.getCpId().equals(getCurrentCpId())) {
String txtContent = numPack.getNumbers()
String pathName = numPack.getName()
byte[] result = txtContent.getBytes()
OutputStream outputStream = response.getOutputStream()
try {
response.reset()
response.setHeader("Content-disposition", "attachment;filename=" +
URLEncoder.encode(pathName, "UTF-8") + ".txt")
response.setContentType("application/force-download")
outputStream.write(result)
outputStream.flush()
}
finally {
if (outputStream != null) {
outputStream.close()
}
}
}
}
return RestResult.failure()
}