blob: e1eebe796006ee76cd24e49655a3379810b38047 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package test;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
class Greeter {
static PrintStream out = System.out;
public static String convertStreamToString(InputStream is) throws Exception {
try (Scanner s = new Scanner(is)) {
s.useDelimiter("\n");
return s.hasNext() ? s.next() : "";
}
}
public void hello(String obj) throws Exception {
String greeting = "Hello";
InputStream stream = Greeter.class.getResourceAsStream("/greeting.txt");
if (stream != null) {
greeting = convertStreamToString(stream);
}
out.println(greeting + " " + obj);
}
public static void main(String... args) throws Exception {
Greeter g = new Greeter();
String obj = args.length > 0 ? args[0] : "world";
g.hello(obj);
}
}
|