jdk1.6或更低版本的java.nio.file.Files替代方案
我正在尝试对以下代码使用java.nio.file.Files功能jdk1.6或更低版本的java.nio.file.Files替代方案,java,java-7,Java,Java 7,我正在尝试对以下代码使用java.nio.file.Files功能 @RequestMapping(value = "/view", method = RequestMethod.GET) public HttpServletResponse viewReport(Map model, HttpServletRequest req,HttpServletResponse rep){ try { ReportGenerationService reportGener
@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;
}
但由于LinuxBox jdk版本较旧(Java6),因此我不能使用它。在Java6中是否有其他方法可以执行类似的操作?提前感谢提供了一个类似于java.nio.file.Files
的类。它有一个重载方法,例如
public static void copy(File from, OutputStream to) throws IOException
那
将文件中的所有字节复制到输出流
它不需要任何Java 7类,因此使用Java 6进行编译。您可以签出并使用它。