|
@@ -310,16 +310,27 @@ public class GenerateCodeServiceImpl implements GenerateCodeService {
|
|
FileItem fileItem = factory.createItem(fileName, "text/plain", true, file.getName());
|
|
FileItem fileItem = factory.createItem(fileName, "text/plain", true, file.getName());
|
|
int bytesRead = 0;
|
|
int bytesRead = 0;
|
|
byte[] buffer = new byte[8192];
|
|
byte[] buffer = new byte[8192];
|
|
|
|
+ FileInputStream fis =null;
|
|
|
|
+ OutputStream os = null;
|
|
try {
|
|
try {
|
|
- FileInputStream fis = new FileInputStream(file);
|
|
|
|
- OutputStream os = fileItem.getOutputStream();
|
|
|
|
|
|
+ fis = new FileInputStream(file);
|
|
|
|
+ os = fileItem.getOutputStream();
|
|
while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
|
|
while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
|
|
os.write(buffer, 0, bytesRead);
|
|
os.write(buffer, 0, bytesRead);
|
|
}
|
|
}
|
|
- os.close();
|
|
|
|
- fis.close();
|
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.warn("文件读取异常",e);
|
|
|
|
+ }finally {
|
|
|
|
+ try {
|
|
|
|
+ os.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.warn("文件流关闭失败",e);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ fis.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.warn("文件流关闭失败",e);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
|
|
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
|