Java - Leer ficheros en java

 
Vista:

Leer ficheros en java

Publicado por Bryan (1 intervención) el 10/02/2021 02:44:01
Tengo un fichero de 500 bytes y de 10 lienas en cada linea hay un String de 30 bytes y 5 numeros=20 bytes en total 50 bytes por cada linea.
quiero comprar un nombre que lo paso como parametro a crecarAdversari pero el problema es que no avanza con seek siempre me sale el primer nombre


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public int[] cercarAdversari(String nomAdv) throws FileNotFoundException, IOException {
 
    RandomAccessFile raf = new RandomAccessFile("Adversaris", "r");
    int cont = 0;
    raf.seek(30 * cont);
    while (raf.getFilePointer() < raf.length()) {
        String x = llegirNom(raf);
 
        if (x.equalsIgnoreCase(nomAdv)) {
            System.out.println("Son iguales");
        }
        raf.skipBytes(20);
        cont++;
    }
    raf.close();
    return null;
 
}

este es mi funcion con la que leo el string

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public String llegirNom(RandomAccessFile raf) throws FileNotFoundException, IOException {
    boolean nomLlegit = false;
    raf = new RandomAccessFile("Adversaris", "r");
 
    String nom = "";
 
    char lletras = raf.readChar();
    while (!(lletras == 0)) {
        nom += lletras;
        lletras = raf.readChar();
        nomLlegit = true;
    }
 
    raf.close();
    if (nomLlegit) {
        return nom;
    } else {
 
        return null;
    }
 
}



Alguien sabe porque no avanza me refiero a q quiero leer el siguinete nombre q empieza en 50 y el otro en 100 y asi hasta llegar al ultimo nombre
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder