How can I write 'one bit' into a file stream or file structure each time?
Is it possible to write to a queue and then flush it?
Is it possible with C# or Java?
This was needed when trying to implement an instance of Huffman coding. I can't write bits into files, so write them to a bitset and then (when compression was completed) write 8-bit piece of it each time (exclude last one).
The issue here is that many platforms do not have direct bit access.  They group bits into a minimal package, often times the byte or word.  Also, the protocol for stream devices does not facilitate transmission of individual bits.  
The common method to deal with individual bits is to pack them into the smallest portable and (addressable) accessible unit.  The unused bits are usually set to zero.  This can be accomplished with binary arithmetic operations (OR, AND, EXCLUSIVE-OR, NOT, etc.).
With modern processors, bit twiddling slows down the machine and the performance.  Memory is cheap and with large addressing spaces, justification for bit packing has become more difficult.  Generally, bit packing is reserved for hardware oriented operations (and also transmission protocols).  For example, if a processor's word capacity is 16 bits, the processor can probably handle 16 words faster than 16 bit manipulations in one word. 
Also, keep in mind that writing to and from memory is often faster than I/O from streams.  Efficient systems buffer data in memory before transmitting the data.  You may want to consider this technique in your designs.  Reducing I/O operations will improve the performance of your program.
Writing 'bits' to C++ file streams