I've managed to feed in a text file (A) into my program and store it in a hashSet. However, i need to feed in another two text files (A and C) and store them also in HashSets. The purpose being, i need to compare A and B to check if they conain any of the same words, than compare Band C and again check if the two files have any of the same words. This is supposed to be an authorship attribution program, so C will than be attributed to the file that it was most similar to.
Each file should be stored in its own hashset.
How can i change the code to enable it to feed in two other text files and store them?
public class FileIn {
// assigns BufferedReader an instance name to be used in the code
BufferedReader in;
HashSet set;
public FileIn() {
try {
// make sure there is a text file in the
java directory where the java
// code is saved
in = new BufferedReader(new FileReader("C:\\Program Files\\Java\\example.txt"));
set = new HashSet();
int Len = 1;
while(Len>0) {
String line = in.readLine();
try {
Len = line.length();
System.out.println(line);
set.add(line);
} catch(NullPointerException npe){
Len = 0; //no more file to read
}
}
public static void main(String args[]) {
//this gets executed when the java file is run
//this then (starting from the top) does what u tell it
FileIn newFile = new FileIn();
}
}