关闭流
This commit is contained in:
parent
22b411ed98
commit
993eacc8b2
|
|
@ -214,13 +214,9 @@ public class FileMongoServiceImpl {
|
|||
FileInputStream inputStream = new FileInputStream(file);
|
||||
// 创建一个与文件大小相等的字节数组
|
||||
byte[] fileContent = new byte[(int) file.length()];
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
// 读取文件内容到字节数组
|
||||
fis.read(fileContent);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
fis.read(fileContent);
|
||||
fis.close();
|
||||
MongoFile mongoFile = mongoFileRepository.save(
|
||||
MongoFile.builder()
|
||||
.fileName(file.getName())
|
||||
|
|
@ -232,7 +228,7 @@ public class FileMongoServiceImpl {
|
|||
.md5(Md5Util.getMd5(inputStream))
|
||||
.build()
|
||||
);
|
||||
|
||||
inputStream.close();
|
||||
return new FileExportVo(mongoFile);
|
||||
}
|
||||
public FileExportVo saveGridFsFile(File file) throws Exception {
|
||||
|
|
@ -252,6 +248,7 @@ public class FileMongoServiceImpl {
|
|||
.gridFsId(gridFsId)
|
||||
.build()
|
||||
);
|
||||
inputStream.close();
|
||||
return new FileExportVo(mongoFile);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue