Normally we write to files in the form of characters.
Is there any way so that we can write data to the file in the form
single bits like five `0's and then six `1's etc.
Knute Johnson - 27 Oct 2007 18:57 GMT
> Normally we write to files in the form of characters.
> Is there any way so that we can write data to the file in the form
> single bits like five `0's and then six `1's etc.
Yes but you will have to write them in groups of 8. But why would you
want to do this? Do you need to write trillions of bits? Why not just
use some simple scheme to represent them for example characters 0 and 1
or byte values 0 and 1? Java has a really neat class called BitSet.
You could store one of those if you wanted.

Signature
Knute Johnson
email s/nospam/knute/
Roedy Green - 27 Oct 2007 21:11 GMT
>Normally we write to files in the form of characters.
>Is there any way so that we can write data to the file in the form
>single bits like five `0's and then six `1's etc.
the smallest unit you can write to a file is a byte. To write bits
you must compose them into bytes first.
See http://mindprod.com/applet/fileio.html
for how to write bytes.
See http://mindprod.com/jgloss/binary.html for basic bit twiddling.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com