我有一个返回 的方法ResponseEntity(InputStreamResource) .在这种方法中,我根据文件名输入从文件中获取 InputStream,然后将 InputStreamResource 作为响应发送。
代码片段
InputStream inputStream = ...;
ResponseEntity<InputStreamResource> response = new ResponseEntity<InputStreamResource>(new InputStreamResource(inputStream), headers, HttpStatus.OK);
return response;
这里我需要关闭 inputStream 对象吗?如果我这样做,我会得到
IllegalStateException: Closed message. Do I need to explicitly close them or container will take care.
最佳答案
处理这个的底层类是 ResourceHttpMessageConverter从 here 可以明显看出,它关闭了底层输入流
关于spring-mvc - 如何在 Spring MVC 中处理 IO 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48660011/