Writing data to binary file.
I am a begginer in programming with Java. I have to write a simple program which can compress a .txt file (for example dictionary).
- loading dictionary to memory (done)
- building Huffman's tree (done)
- writing it to .bin file (here is a problem)
When I try to write my String (for example "011011") to .bin I have much bigger file than .txt, I have to convert it to binary type and save bit after bit but I have no idea how to do that. What should I do first? I have string and I have to save it to a .bin file. Maybe could anyone write a function which may do that?
prototype of function:
public void saveToBin(String txt)
Re: Writing data to binary file.
No one will write the method for you, but we can direct you to the correct place.
I'm not 100% sure, but I would say that you need to use a Byte Stream. Here is a brief tutorial that you should find helpful: Byte Streams (The Java™ Tutorials > Essential Classes > Basic I/O)