我尝试使用nio通过API下载照片文件,但不确定如何创建响应渠道,此代码正确吗?
@RequestMapping(value = "/photosFast/{filename}.jpg", method = RequestMethod.GET)
@ResponseBody
...
FileChannel srcChannel = new FileInputStream(src.getAbsolutePath()).getChannel();
FileChannel destChannel = new FileOutputStream(response.getHeader("localtion")).getChannel();
try {
srcChannel.transferTo(0, srcChannel.size(), destChannel);
} finally {
srcChannel.close();
destChannel.close();
}
...