Hi when I read the file with readUTF() method, the console output displays the atributtes separately. For example, I have this code:
public void grabarFichero(String clave, String nombre, String edad, String sueldo)
{
int i;
String datos[] = new String[4];
datos[0] = clave;
datos[1] = nombre;
datos[2] = edad;
datos[3] = sueldo;
try
{
rafObj = new RandomAccessFile(fileName, "rw");
rafObj.seek(rafObj.length());
for(i=0; i<datos.length; i++)
{
rafObj.writeUTF(datos[i]);
}
}
}
public void leerFichero()
{
String clave, nombre, edad, sueldo;
JTextArea area = new JTextArea();
try
{
rafObj = new RandomAccessFile(fileName, "r");
rafObj.seek(0);
rafObj.seek(0);
while(rafObj.getFilePointer()<rafObj.length())
{
System.out.println(rafObj.readUTF());
}
}
So, the output is this:
AF
Amaro
25
1500
LO
Bea
45
6258
It is essential to use RandomAccesFile class but the problem is that if I search ("clave: AF" for example) the program has to return "nombre: Amaro", "edad: 25" and "sueldo: 1500". If I search ("clave: LO") the program has to return "nombre: Bea", "edad: 45" and "sueldo: 6258".