我正在春季启动。我有一种使用字节数组返回文件的方法。而我试图返回字节数组时出现此错误。我的代码如下-
@GetMapping(
value = "/get-file",
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE
)
public @ResponseBody byte[] getFile() throws IOException {
InputStream in = getClass()
.getResourceAsStream("/com/baeldung/produceimage/data.txt");
return IOUtils.toByteArray(in);
}
Run Code Online (Sandbox Code Playgroud)