java - java.nio.file.InvalidPathException:格式错误的输入或输入包含不可映射的字符
问题描述
我正在尝试从 Spring 端点下载 pdf 文件。我试过这个:
@RequestMapping("/download_files/{merchant_id}")
public ResponseEntity<byte[]> downloadFile(@PathVariable("merchant_id") Integer merchant_id) throws IOException {
File initialFile = new File("/opt/1/www.pdf");
InputStream in = FileUtils.openInputStream(initialFile);
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_PDF);
return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED);
}
但我得到错误:
2019-08-20 21:02:25,658 INFO [stdout] (default task-307) java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: /opt/1/25084 BRP (BrookfieldDC.com Site Architecture & Creative?Phase 2) Autoresponders (1).pdf
你知道我该如何解决这个问题吗?