< prev index next >
test/jdk/tools/jpackage/apps/image/Hello.java
Print this page
@@ -19,48 +19,30 @@
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* 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);
- }
-
- private static void printToStdout(String[] args) {
- System.out.println(MSG);
-
- System.out.println("args.length: " + args.length);
-
- for (String arg : args) {
- System.out.println(arg);
- }
+ public static void main(String[] args) throws IOException {
+ printArgs(args, System.out);
- 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);
+ try (PrintStream out = new PrintStream(new BufferedOutputStream(
+ new FileOutputStream("appOutput.txt")))) {
+ printArgs(args, out);
}
}
- }
-
- 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)))) {
+ private static void printArgs(String[] args, PrintStream out) {
out.println(MSG);
out.println("args.length: " + args.length);
for (String arg : args) {
@@ -71,10 +53,7 @@
String value = System.getProperty("param" + index);
if (value != null) {
out.println("-Dparam" + index + "=" + value);
}
}
- } catch (Exception ex) {
- System.err.println(ex.getMessage());
- }
}
}
< prev index next >