title: How to Search for a String in a RandomAccessFile with this code?
body: <p>I am trying to make a little search method, and up to now I have one that only searches int types, I've been wondering if its somehow possible to re implement this method to search Strings? </p>
  
  <pre><code>//Searches only ints
  public void buscarCliente_Codigo(int cod) throws IOException{ /*cod is for the input
  for eg. a textfield input which im using*/
  
  try{
  RandomAccessFile f = new RandomAccessFile("Clientes.txt","rw"); //.txt File name
  boolean encontrado=false;
  registroExistente = false ;
  long bytes = 0;
  do{
  codigo = f.readInt();
  nombre = leerNombre(f);    //Reads String
  numTelefono = leerNumTelefono(f);
  direccion = leerDireccion(f);
  seguro = leerSeguro(f);
  nacionalidad = leerNacionalidad(f);
  cedula = leerCedula(f);
  if(cod==codigo){
  iCodigoBusqueda = codigo;
  encontrado=true;
  registroExistente = true;
  break;
  }else{
  iCodigoBusqueda = 0;  //Type int
  registroExistente = false;
  }
  bytes +=1;//Changes
  f.seek(bytes);
  }
  while(bytes&lt;f.length());
  f.close();
  }  catch (Exception e){
  registroExistente = false;
  JOptionPane.showMessageDialog(null,"Data not found");
  
  }
  }
  </code></pre>
  
  <p>After doing that I just code a couple of .getText and I have a beautiful search mechanism that only works with number, but I really want a method that searches for Strings, So I made a couple of tweeks:</p>
  
  <pre><code>**enter code here**
  public void buscarCliente_Nombre(String nom) throws IOException{ //change to String
  
  try{
  RandomAccessFile f = new RandomAccessFile("Clientes.txt","rw");
  boolean encontrado=false;
  registroExistente = false ;
  long bytes = 0;
  do{
  codigo = f.readInt();
  nombre = leerNombre(f);
  numTelefono = leerNumTelefono(f);
  direccion = leerDireccion(f);
  seguro = leerSeguro(f);
  nacionalidad = leerNacionalidad(f);
  cedula = leerCedula(f);
  if(nom.equals(nombre)){
  iNombreString = nombre;
  encontrado=true;
  registroExistente = true;
  break;
  }else{
  iNombreString = ""; //String type
  registroExistente = false;
  }
  bytes +=1;//cambios
  f.seek(bytes);
  }
  while(bytes&lt;f.length());
  f.close();
  }  catch (Exception e){
  registroExistente = false;
  JOptionPane.showMessageDialog(null,"Data not found");
  
  }
  
  }
  </code></pre>
  
  <p>It doesn't work, it gives me the Exception. </p>
  
  <p>So is there anyway this code would work for Strings_?. </p>
  
  <p>thanks</p>