简体   繁体   中英

Insert binary data into a 2D Array

I'm trying to read a binary file (.dat) and save all of this stuff in a 2D array. The number of rows is defined as the number of lines in the binary file, and the number of columns is defined as 9. So, I want to be able to detect -1's in the lines of the binary file, and fill the 2D array skipping those values. I'm currently using the following code, but it will only delete one row, even though there is more than one line with negative ones in the binary file.

RandomAccessFile Archivocopiadora = new RandomAccessFile("Archivos/CopiadorasAgregadas.dat", "rw");
cantRegistros = Archivocopiadora.length()/tamRegistro;
matrizcopiadorascargadas = new String[(int)cantRegistros][9];
contadorespaciosvacios = 0;
int registroenceros = 0;
String lecturacopiadoraa = "";

for(int registro = 0; registro < cantRegistros; registro++) {
    Archivocopiadora.seek(registro * tamRegistro + 88);
    int prueba = Archivocopiadora.readInt();

    if (prueba == -1) {
        contadorespaciosvacios++;
        stdOut.println(contadorespaciosvacios);
        List<String[]> l = new ArrayList<String[]>(Arrays.asList(matrizcopiadorascargadas));
        l.remove(registro);
        array2 = l.toArray(new String[l.size()][9]);
    } else {
        Archivocopiadora.seek(registro * tamRegistro);
        for (int ex = 0; ex < 40; ex++)
            lecturacopiadoraa = lecturacopiadoraa + Archivocopiadora.readChar();

        lecturacopiadoraa.trim();
        matrizcopiadorascargadas[registro][0] = lecturacopiadoraa;
        matrizcopiadorascargadas[registro][1] = Double.toString(Archivocopiadora.readDouble());
        matrizcopiadorascargadas[registro][2] = Integer.toString(Archivocopiadora.readInt());
        matrizcopiadorascargadas[registro][3] = Integer.toString(Archivocopiadora.readInt());
        matrizcopiadorascargadas[registro][4] = Integer.toString(Archivocopiadora.readInt());
        matrizcopiadorascargadas[registro][5] = Double.toString(Archivocopiadora.readDouble());
        matrizcopiadorascargadas[registro][6] = Double.toString(Archivocopiadora.readDouble());
        matrizcopiadorascargadas[registro][7] = Double.toString(Archivocopiadora.readDouble());
        matrizcopiadorascargadas[registro][8] = Double.toString(Archivocopiadora.readDouble());
        lecturacopiadoraa = "";
    }
}

When you decide to "delete" a row, you create a new list of string-arrays, remove the desired row from it, and convert THAT to an array, which gets assigned to array2 -- which I don't see declared anywhere. In particular, you don't seem to be doing anything to matrizcopiadorascargadas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM