--- old/test/jdk/tools/jpackage/apps/image/Hello.java 2019-09-18 10:33:16.962963200 -0400 +++ new/test/jdk/tools/jpackage/apps/image/Hello.java 2019-09-18 10:33:15.443129000 -0400 @@ -21,60 +21,39 @@ * questions. */ -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; +import java.io.BufferedOutputStream; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.io.IOException; public class Hello { private static final String MSG = "jpackage test application"; private static final int EXPECTED_NUM_OF_PARAMS = 3; // Starts at 1 - public static void main(String[] args) { - printToStdout(args); - printToFile(args); + public static void main(String[] args) throws IOException { + printArgs(args, System.out); + + try (PrintStream out = new PrintStream(new BufferedOutputStream( + new FileOutputStream("appOutput.txt")))) { + printArgs(args, out); + } } - private static void printToStdout(String[] args) { - System.out.println(MSG); + private static void printArgs(String[] args, PrintStream out) { + out.println(MSG); - System.out.println("args.length: " + args.length); + out.println("args.length: " + args.length); for (String arg : args) { - System.out.println(arg); + out.println(arg); } for (int index = 1; index <= EXPECTED_NUM_OF_PARAMS; index++) { String value = System.getProperty("param" + index); if (value != null) { - System.out.println("-Dparam" + index + "=" + value); - } - } - } - - private static void printToFile(String[] args) { - String outputFile = "appOutput.txt"; - File file = new File(outputFile); - - try (PrintWriter out - = new PrintWriter(new BufferedWriter(new FileWriter(file)))) { - out.println(MSG); - - out.println("args.length: " + args.length); - - for (String arg : args) { - out.println(arg); - } - - for (int index = 1; index <= EXPECTED_NUM_OF_PARAMS; index++) { - String value = System.getProperty("param" + index); - if (value != null) { - out.println("-Dparam" + index + "=" + value); - } + out.println("-Dparam" + index + "=" + value); } - } catch (Exception ex) { - System.err.println(ex.getMessage()); } } }