I have a BitSet and you want to write it to a file - I came across a decision to use ObjectOutputStream using the writeObject method.
I looked at ObjectOutputStream in the java API and saw that you can write other things (bytes, int, short, etc.)
I tried to check the class, so I tried to write a byte to a file using the following code, but the result gives me a file with 7 bytes instead of 1 byte
My question is: what are the first 6 bytes in the file? why are they there?
my question relates to BitSet, because I do not want to start writing a large amount of data to a file and understand that I have random bytes inserted into the file, not knowing what they are.
here is the code:
byte[] bt = new byte[]{'A'}; File outFile = new File("testOut.txt"); FileOutputStream fos = new FileOutputStream(outFile); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.write(bt); oos.close();
thanks for any help
Avner
java objectoutputstream bitset
Avner
source share