I was having to create an index with a book passed by parameter ( File
, BufferedReader
).
So far I have not gotten good results, I only have one code that generates a TreeSet
with all the words of the text passed by parameter. I'm trying for 3 weeks to make the code that takes the words and save the lines where they appear and generate the index HTML file.
Read
is a LineNumberReader
, words is a TreeSet
.
I have encountered problems when I go through the list generated by the split method and compare it with the text word by word (this is the code I can not compile).
while((line = read.readLine()) != null){
line = line.replaceAll("[^a-zA-Z]", " ").toLowerCase();
split = line.split(" ");
for(String s : split){
if(s.length() >= 1 && !palavras.contains(s)){
palavras.add(s);
}
}
}
path.close();
read.close();
}catch(FileNotFoundException e){
e.getStackTrace();
System.out.println("Caminho para o arquivo invalido!");
}catch(IOException ex){
ex.getStackTrace();
}
return palavras;
}