0

huge apologies if this has been asked before, I did search but nothing seemed to cover the problem I have.

I am a complete novice in Java btw.

My problem is this:

So far I have loaded the file as follows:

            int element = 0;
        for (int count = 0; count < numberOfLines; count++) {
            List<String> range = Arrays.asList(lines.get(count));
            String splitRange = String.valueOf(range.get(element));
            element++;
            int myHash = (int) splitRange.get(element);
                byte myKey = (byte) range[element];
                byte[] ib = (byte[]) range[element];
                byte[] myCheck = (byte[]) range[element];
                byte[] myCat = (byte[]) range[element];
                byte[] myDel = (byte[]) range[element];
            if (element > 5){
                element = 0;
            }

        }

I have a generated file that contains lines of in this format:

[-1284234074, 1, [101, 97, 51, 97, 54, 57, 49, 48], [7, 90, 116, -56, 105, -90, -23, 84, 101, 56, 99, -59, 19, 88, -55, -2], [-107, -101, -58, -45, -120, -42, -60, -81, -58, -104, -78, -110, -67, -86, -123, -120], [-126, -119, -119, -128, -120, -114, -111, -128, -123, -126, -120, -94, -125, -121, -128, -126]]

Now, this is supposed to be the following:

int, byte, byte[], byte[], byte[], byte[]

How on earth can I split this line in to these variables?

Dave
  • 11
  • 3
  • 1
    Do you really need to invent your own file format. Use JSON or if you insist on compact byte arrays use Binary JSON https://en.wikipedia.org/wiki/BSON – bhspencer Apr 11 '18 at 14:22
  • Thanks, just being pointed in the right direction worked miracles. much appreciated. – Dave Apr 11 '18 at 14:53

1 Answers1

-2

I'm assuming you are facing difficulties in reading the file and creating a Java Object from file.

Try writing serialized objects into the file. That way, your object is automatically created while de-serializing.

Prudvinath
  • 15
  • 1
  • 5