| | |
| | | WordExtractor wordExtractor = new WordExtractor(doc);
|
| | | return wordExtractor.getText();
|
| | | }
|
| | | case "text/plain":
|
| | | _logger.info("文件类型是 TXT");
|
| | | byte[] fileData = readAttachFile(file);
|
| | | return new String(fileData, "UTF-8");
|
| | | default:
|
| | | _logger.info("未知文件类型: " + mimeType);
|
| | | break;
|
| | |
| | | _logger.error("文件处理失败: " + e.getMessage());
|
| | | throw new Exception("文件处理失败: " + e.getMessage());
|
| | | }
|
| | | return null;
|
| | | return "";
|
| | | }
|
| | | public static byte[] readAttachFile(MultipartFile file) throws Exception
|
| | | {
|
| | | InputStream is = file.getInputStream();
|
| | | ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
| | | byte[] data = new byte[1024 * 1024];
|
| | | while(true)
|
| | | {
|
| | | int size = is.read(data);
|
| | | if(size <= 0)
|
| | | return bos.toByteArray();
|
| | |
|
| | | bos.write(data, 0, size);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|