diff -r bf06a1d3aef6 -r e0efb29609bd test/jdk/tools/jpackage/apps/image/Hello.java --- a/test/jdk/tools/jpackage/apps/image/Hello.java Mon Sep 16 19:24:32 2019 -0400 +++ b/test/jdk/tools/jpackage/apps/image/Hello.java Tue Sep 24 13:41:16 2019 -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); + 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); - } - } - } catch (Exception ex) { - System.err.println(ex.getMessage()); - } - } }