-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainClass.java
More file actions
52 lines (41 loc) · 1.59 KB
/
Copy pathMainClass.java
File metadata and controls
52 lines (41 loc) · 1.59 KB
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
import java.io.*;
import java.util.Scanner;
/**
* main driver class
*/
public class MainClass
{
private static Scanner kb = new Scanner (System.in); // handles console input
private static FileReader f;
private static BufferedReader b;
private static Tokenizer t;
private static String srcFileName = ""; // empty name of file to read from
private static String destFileName = "WORDS.txt"; // name of file to write to
private static String input = "";
private static String token;
private static BinarySearchTree tree = new BinarySearchTree(); // creates a binary search tree
public static void main(String[] args)
{
try
{
System.out.print("Input filename: ");
srcFileName = kb.next();
f = new FileReader(srcFileName);
b = new BufferedReader(f);
t = new Tokenizer(b, token, input, tree);
t.Tokenize(); // parses the input sentences into tokens
tree.Write(destFileName); // sorts the BST and writes contents to an output file
f.close(); // closes the FileReader stream
b.close(); // closes the BufferedReader stream
BinarySearchTree.Destroy(tree.root); // destroys and clears the BST
}
catch (FileNotFoundException e) // goes here if the input file could not be found
{
System.out.println(srcFileName + " not found.");
}
catch (IOException e) // debugging purposes only
{
//System.out.println("Error in input or file closing.");
}
}
}