Reputation: 70
I'm having trouble getting a bit to work properly in java6...I'm trying to write a compression program that will write bits to a compressed file...so for example a common letter such as "e" might just be the binary sequence "101" in ascii
I think the fileOutputStream.write(int)
method is what I'm going to want to accomplish this, but how to I represent a sequence of bits as in int?
Upvotes: 2
Views: 1764
Reputation: 533500
101 is the ascii value for 'e'
All you have to is write it
FileOutputStream fos =
fos.write('e'); // writes 101 which is the ascii for 'e'
Upvotes: 0
Reputation: 137322
You can use BitSet
. And then write a full byte array using FileOutputStream#write(byte\[\])
like that:
fileOutputStream.write(myBitSet.toByteArray());
Upvotes: 3