-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.java
More file actions
44 lines (36 loc) · 1015 Bytes
/
parser.java
File metadata and controls
44 lines (36 loc) · 1015 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Venkata Harish Kajur 8982
* Jonathan Lysiak 4477
*
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class parser {
private static void readFile(String fileName) {
try {
File file = new File(fileName);
Scanner scanner = new Scanner(file);
while (scanner.hasNext()) {
String s = scanner.next().replaceAll("[^A-Za-z0-9]", " ").toLowerCase();
s = s.replaceAll("[ ][ ]*", " ");
s = s.replaceAll("^[ ]*", "");
String[] strArray = s.split(" ");
for(String str : strArray)
if(!str.isEmpty() && str.trim().length() > 0)
System.out.println(str);
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace(); //Prints errors if file not found
}
}
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("usage: java TextScanner1"
+ "file location");
System.exit(0);
}
readFile(args[0]);
}
}