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();
}