Issue #3628 - Closed unclosed input stream

This commit is contained in:
Adam InTae Gerard 2018-02-09 22:55:34 -08:00 committed by GitHub
parent d4522c7c16
commit c67eca5faa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -25,14 +25,20 @@ public class MultipartController {
try {
InputStream in = file.getInputStream();
String path = new File(".").getAbsolutePath();
FileOutputStream f = new FileOutputStream(path.substring(0, path.length()-1)+ "/uploads/" + file.getOriginalFilename());
int ch;
while ((ch = in.read()) != -1) {
f.write(ch);
FileOutputStream f = new FileOutputStream(path.substring(0, path.length() - 1) + "/uploads/" + file.getOriginalFilename());
try {
int ch;
while ((ch = in.read()) != -1) {
f.write(ch);
}
modelAndView.getModel().put("message", "File uploaded successfully!");
} catch (Exception e) {
System.out.println("Exception uploading multipart: " + e);
} finally {
f.flush();
f.close();
in.close();
}
f.flush();
f.close();
modelAndView.getModel().put("message", "File uploaded successfully!");
} catch (Exception e) {
System.out.println("Exception uploading multipart: " + e);
}