-
Notifications
You must be signed in to change notification settings - Fork 1
/
InputSource.java
executable file
·59 lines (52 loc) · 1.24 KB
/
InputSource.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.*;
import java.io.*;
// A class that generates lines from the input.
public class InputSource {
private BufferedReader in;
public InputSource ( ) {
try {
in = new BufferedReader (new InputStreamReader (System.in));
} catch (Exception e) {
System.err.println ("Couldn't access keyboard!");
System.exit (1);
}
}
public InputSource (String fileName) {
try {
in = new BufferedReader (new InputStreamReader (new FileInputStream (fileName)));
} catch (Exception e) {
System.err.println ("Couldn't access file!");
System.exit (1);
}
}
public String readLine ( ) {
String line = "";
try {
line = in.readLine ( );
} catch (IOException e) {
System.err.println ("input error");
System.exit (1);
}
if (line == null) {
return null;
}
// Added call to trim: March 18, 2011.
return line.toLowerCase ( ).trim ( );
}
public static void main (String [ ] args) {
InputSource in;
if (args.length == 0) {
in = new InputSource ( );
} else {
in = new InputSource (args[0]);
}
String s;
while (true) {
s = in.readLine ( );
if (s == null) {
System.exit (0);
}
System.out.println (s);
}
}
}