Java代码:
ByteArrayInputStream streamInput = object.getContent();
...
// what should i do :)
...
Map<String, Object> returnData = new HashMap<>();
returnData.put("streamFile", streamFile);
return new ResponseEntity<Map<String, Object>>(returnData, HttpStatus.OK);
我有ByteArrayInputStream
,我希望将此ByteArrayInputStream
转换为javascript文件。我已经这样做了:
int n = streamInput.available();
byte[] bytes = new byte[n];
streamInput.read(bytes, 0, n);
String stringFile = new String(bytes, StandardCharsets.UTF_8);
...
returnData.put("streamFile", stringFile);
return new ResponseEntity<Map<String, Object>>(returnData, HttpStatus.OK);
我得到了字符串,但是我不知道如何将其转换为文件。有人知道吗?