I have created a hashmap> called myMap and i want to store all unique words in the keys of Hashmap and names of the files in values corresponding to key words. taking input from multiple files and storing their names in values corresponding to key words.
Sample input from 1 file
AS YOU LIKE IT
by William Shakespeare
DRAMATIS PERSONAE.
DUKE, living in exile
FREDERICK, his brother, and usurper of his dominions
AMIENS, lord attending on the banished Duke
JAQUES, " " " " " "
LE BEAU, a courtier attending upon Frederick
CHARLES, wrestler to Frederick
OLIVER, son of Sir Rowland de Boys
JAQUES, " " " " " "
Code
String name = f.getName();
BufferedReader in = new BufferedReader(new FileReader(f));
String words = in.readLine().trim().toLowerCase();
for(String word: words.split("\\s+")) {
if (myMap.get(word) == null) {
myMap.put(word, new ArrayList<String>());
}
myMap.get(word).add(name);
}
i am able to read only first line from all the files..