3
I have a small application that requires a search engine capable of listing the files that contain a term informed by the user.
The first functionality of the program, which is responsible for informing how many times a string appears within a file .txt
, is already completed.
Below is the code of 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 someone give me a light on how to implement this search engine?
Related: List directory and subdirectory files with listFiles
– Math
Hey, come on, man. List directory files I already know, the same problem is to check which files have a certain string informed by the user. Thank you for the reply.
– hofmanng
String inside the file? Or in its name?
– Math
Inside the archive.
– hofmanng