forked from softwareconstruction240/softwareconstruction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScannerExample.java
More file actions
29 lines (24 loc) · 803 Bytes
/
ScannerExample.java
File metadata and controls
29 lines (24 loc) · 803 Bytes
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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ScannerExample {
public static void main(String[] args) throws FileNotFoundException {
ScannerExample scannerExample = new ScannerExample();
if(args.length == 1) {
scannerExample.processFile(args[0]);
} else {
scannerExample.usage();
}
}
public void processFile(String filePath) throws FileNotFoundException {
File file = new File(filePath);
Scanner scanner = new Scanner(file);
while(scanner.hasNext()) {
String str = scanner.next();
System.out.println(str);
}
}
private void usage() {
System.out.println("\nUSAGE: java ScannerExample <input-file>");
}
}