Hi everyone,
I'm working on a small project and have run into some problems.
Briefly described, what I'm attempting to do is:
I've a rather large text file with a different sentence and I need to find all the words in each sentence and add them to some sort of index, so that the structure is: key = word and value = line number(s). For example like this:
mistake | 0, 2, 4, 6
sun | 0, 1, 5, 10
rain | 3, 4, 10, 22
I need to make a tool to find the occurrence of a word in a file, so if I search for the word "drum" is say: Drum occur 5 times in line 3, 8, 9, 11, 32
I've played around with some different structures but unfortunately I haven't been successful.
I read my text file as such:
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
while (true) {
String str = br.readLine();
if (str == null) break;
lines.add(str);
}
Any help would be appreciated.
Sincere
- Mestika