In one file, I save a TreeNode object, then an int, and then a byte array to a file named `huffmanTrial.huff`.
In another file I want to read in all three of those things and do work on them. I can read in the TreeNode just fine and the int, but when I get to reading in the byte array I get that it is of size zero. Is that saying that it doesn't exist? I am using `in.available()` after I read in the TreeNode and int so I can see how big I need to make my new byte array and I always get 0. Am I somehow saving the array wrongly or am I reading it in wrongly?
Here is where I save the objects:
And here is where I am trying to read all three things in
FileInputStream fis = new FileInputStream("huffmanTrial.huff"); ObjectInputStream in = new ObjectInputStream(fis); root = (HuffmanNode) in.readObject(); System.out.println("root "+ root.getCount()); numberOfZeroesAdded = in.readInt(); System.out.println("zeroes: "+numberOfZeroesAdded); sizeOfArray = in.available(); System.out.println("Size of array: "+sizeOfArray); encodedByteArray = new byte[sizeOfArray]; in.readFully(encodedByteArray);
I get `Size of array: 0`
I know for sure that the array that I am saving is not empty because just two lines before I save it, I print its contents. What am I doing wrong?