diff --git a/toolsrc/org/mozilla/javascript/tools/jsc/Main.java b/toolsrc/org/mozilla/javascript/tools/jsc/Main.java index 9a11a63f6e..eccd7a0c4c 100644 --- a/toolsrc/org/mozilla/javascript/tools/jsc/Main.java +++ b/toolsrc/org/mozilla/javascript/tools/jsc/Main.java @@ -240,11 +240,8 @@ public void processSource(String[] filenames) { byte[] bytes = (byte[]) compiled[j + 1]; try { File outfile = getOutputFile(targetTopDir, className); - FileOutputStream os = new FileOutputStream(outfile); - try { + try (FileOutputStream os = new FileOutputStream(outfile)) { os.write(bytes); - } finally { - os.close(); } } catch (IOException ioe) { addFormatedError(ioe.toString()); diff --git a/toolsrc/org/mozilla/javascript/tools/shell/Global.java b/toolsrc/org/mozilla/javascript/tools/shell/Global.java index 748b587cad..a5031376ae 100644 --- a/toolsrc/org/mozilla/javascript/tools/shell/Global.java +++ b/toolsrc/org/mozilla/javascript/tools/shell/Global.java @@ -1034,14 +1034,12 @@ private static String readUrl(String filePath, String charCoding, boolean urlIsF is = new FileInputStream(f); } - Reader r; - if (charCoding == null) { - r = new InputStreamReader(is); - } else { - r = new InputStreamReader(is, charCoding); + try (Reader r = + new InputStreamReader( + is, + charCoding == null ? Charset.defaultCharset().name() : charCoding)) { + return readReader(r, chunkLength); } - return readReader(r, chunkLength); - } finally { if (is != null) is.close(); }