我正在尝试对以下代码使用 java.nio.file.Files 功能
@RequestMapping(value = "/view", method = RequestMethod.GET)
public HttpServletResponse viewReport(Map model, HttpServletRequest req,HttpServletResponse rep){
try {
ReportGenerationService reportGenerationService = new ReportGenerationService();
ViewReportParameters viewReportParameters = reportGenerationService.getReportViewParameters();
String quote="\"";
String inlineFileName = "inline; fileName="+quote+viewReportParameters.getFileName()+".pdf"+quote;
File file = new File(filePath);
rep.setHeader("Content-Type", "application/pdf");
rep.setHeader("Content-Length", String.valueOf(file.length()));
rep.setHeader("Content-Disposition", inlineFileName);
Files.copy(file.toPath(), rep.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
return rep;
}
但由于 linux box jdk 版本较旧(Java 6),我不能使用它。在 Java 6 中是否可以进行类似操作?提前致谢