8274809: Update java.base classes to use try-with-resources

Reviewed-by: mullan, alanb, dfuchs
This commit is contained in:
Andrey Turbanov 2022-01-10 16:20:58 +00:00 committed by Daniel Fuchs
parent debaa28e9c
commit dee447f8ae
7 changed files with 20 additions and 58 deletions

View file

@ -68,10 +68,10 @@ public class NetProperties {
File f = new File(fname, "conf");
f = new File(f, "net.properties");
fname = f.getCanonicalPath();
InputStream in = new FileInputStream(fname);
BufferedInputStream bin = new BufferedInputStream(in);
props.load(bin);
bin.close();
try (FileInputStream in = new FileInputStream(fname);
BufferedInputStream bin = new BufferedInputStream(in)) {
props.load(bin);
}
} catch (Exception e) {
// Do nothing. We couldn't find or access the file
// so we won't have default properties...

View file

@ -382,9 +382,7 @@ public class MimeTable implements FileNameMap {
}
protected boolean saveAsProperties(File file) {
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
try (FileOutputStream os = new FileOutputStream(file)) {
Properties properties = getAsProperties();
properties.put("temp.file.template", tempFileTemplate);
String tag;
@ -407,11 +405,6 @@ public class MimeTable implements FileNameMap {
e.printStackTrace();
return false;
}
finally {
if (os != null) {
try { os.close(); } catch (IOException e) {}
}
}
return true;
}