I need to read file stream as bits and then I should be able to write bits to file again. Are there any classes for this purpose?
As far as I know, there is no built in way to do it directly at the bit level. There are ways to read/write byte by byte using the built in streams. You could write a wrapper on a stream that looks like it reads and writes bits.
If you want something that is already written, look for open source projects that do certain kinds of audio or video encoding, since there are things like that. For instance, the FLAC codec had a BitInputStream that might meet your needs.
I was pretty happy with the colt library from CERN. Can't remember if it supports File I/O but I used it to read bitstreams, analyse and modify them and write them back to files.
Preon might be what you are looking for. Looking at your questions, I could imagine that Preon might be even more than what you are looking for.
Think of Preon as a library that provides to bitstream encoded content what Hibernate aims to be to relational databases, and JAXB to XML. Now, it exists of a couple of modules. One of those modules is preon-binding. That's the actual data binding framework. (Driven by annotations.)
However, preon-binding is built on top of preon-bitbuffer (in later incarnations re-dubbed to preon-io). That library has BitBuffer type of abstraction for accessing bitstream compressed data.
The Preon release last summer does not have support for encoding yet. That's work in progress.