Advertisement
robeeeert

Untitled

Jun 24th, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1.     public  void BuscarEnArchivo(String nBuscar){
  2.         try{
  3.             File f = new File("Datos.txt");
  4.             if (f.exists()){
  5.                 FileReader fr = new FileReader(f);
  6.                 BufferedReader br = new BufferedReader(fr);
  7.                 String linea;
  8.                 boolean encontrado = false;
  9.                 while((linea = br.readLine()) !=null){
  10.                     String [] arreglo = linea.split("%");
  11.                     if (arreglo[0].equalsIgnoreCase(nBuscar)){
  12.                         Persona persona = new Persona(arreglo[0], arreglo[1], arreglo[2], arreglo[3], arreglo[4]);
  13.                         System.out.println("Persona Encontrada");
  14.                         System.out.println(persona.toString());
  15.                          encontrado = true;
  16.                     }//ifarreglo
  17.                 }//while
  18.                 br.close();
  19.                 fr.close();
  20.                 if(!encontrado){
  21.                     System.out.println("No hay coincidencias");
  22.                 }
  23.             }//if
  24.         }catch(Exception e){
  25.                 System.out.println("Error de S/N " + e);
  26.         }//TryCatch
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement