public static void main(String[] args) throws IOException {
        FileReader in = null;               // reads in the original file
        ObjectOutputStream out = null;      // writes out the compressed file

        // Check for the file names on the command line.
        if (args.length != 2) {
            System.out.println("Usage: java Huff <in fname> <out fname>");
            System.exit(1);
        }

        // Open the input file.
        try {
            in = new FileReader(args[0]);
        } catch (FileNotFoundException e) {
            System.out.println("Can't open file " + args[0]);
            System.exit(1);
        }

        // Open the output file.
        try {
            out = new ObjectOutputStream(new FileOutputStream(args[1]));
        } catch (FileNotFoundException e) {
            System.out.println("Can't open file " + args[1]);
            System.exit(1);
        }
    
        // Create a BitWriter that is able to write to the compressed file.
        BitWriter writer = new BitWriter(out);

		 int ch;
			while((ch = in.read()) != -1)
			{
				header[ch]++;
				textLength++;
			}
        
        // Create Huffman tree
        createAndFillHuffmanTree(header);
		
		// Write the header to the file
        writeHeader(out, header);
        
        // Open file in a second time
        in = new FileReader(args[0]);
		Code code;
		int bit;
		ch = 0;
		while((ch = in.read()) != -1)
		{
			//System.out.print((char)ch);
			code = huffmanTree.getCode(ch);
			for(int i = 0; i < code.length(); i++)
			{
				bit = code.getBit(code.length()-1 - i);
				//System.out.print(bit);
				writer.putBit(bit);
			}
		}

         //Leave these lines at the end of the method. 
        in.close();
        out.close();
    }