-1

I am trying to get the binary data, "deserialize?" it into usable data from the file statePopulationPercentages.dat.

Then I want to add the integers to an ArrayList<Integer> called percentages, but for starters, just print them out.

I'm really new to java and working with binary files so any help would be great. Here's what I've got so far.

    try {
        // Open the file for reading.
        RandomAccessFile raf = new RandomAccessFile("statePopulationPercentages.dat", "r");

        long position = raf.length();

        while (position > 0) {

            position -= 1;

            raf.seek(position);
            byte b = raf.readByte();

            // line = deserialize "b"

            // add to ArrayList<Integer> percentages
            // percentages.add(line);

            System.out.print((int) b); // this would obviously go away when adding to the array list
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
Alex Cory
  • 10,635
  • 10
  • 52
  • 62

1 Answers1

1

Assuming the file was created by serializing Java objects, this is a page that has info on deserializing the objects into an ArrayList:

Deserialize multiple Java Objects

Community
  • 1
  • 1