I have a small application that needs a search engine that can list files that contain a user-entered term.
The first feature of the program, which is responsible for reporting how many times a string appears within a .txt
file, is already complete.
Here is the code for the first part:
Teclado teclado= new Teclado();
String opcao= teclado.getUserInput("Insira uma palavra: ");
BufferedReader br= new BufferedReader(
new InputStreamReader(
new FileInputStream("arquivo.txt")));
String linha= br.readLine();
int count=0;
while(linha != null){
String palavras[] = linha.split(" ");
for(int i=0; i<palavras.length; i++){
//System.out.println(palavras[i]);
if(opcao.equalsIgnoreCase(palavras[i])){
count++;
}
}
linha= br.readLine();
}
System.out.println(count);
Could anyone give me a light on how to implement this search engine?