title: Java compressing a .txt file
body: <p>I am currently trying to write a program which reads in a compressed file which is written in bits or 0s and 1s, and convert them in to strings of 0s and 1s.</p>
  
  <p>The School provided a class and method for reading 1 bit and converting that in to a character char. So to read and convert one bit to a char, all i need to do is type in my code:</p>
  
  <pre><code>char oneBit = inputFile.readBit();
  </code></pre>
  
  <p>in my main method.</p>
  
  <p>How do I get my program to read over every bit within the compressed file and convert them to char? using the <code>.readBit</code> method? And how would I convert all the char 0s and 1s in to strings of 0s and 1s?</p>
  
  <p>The readBit method:</p>
  
  <pre><code>public char readBit() {
      char c = 0;
  
      if (bitsRead == 8)
          try {
              if (in.available() &gt; 0) { // We have not reached the end of the
                                          // file
                  buffer = (char) in.read();
                  bitsRead = 0;
              } else
                  return 0;
          } catch (IOException e) {
              System.out.println("Error reading from file ");
              System.exit(0); // Terminate the program
          }
  
      // return next bit from the buffer; bit is converted first to char
      if ((buffer &amp; 128) == 0)
          c = '0';
      else
          c = '1';
      buffer = (char) (buffer &lt;&lt; 1);
      ++bitsRead;
  
      return c;
  }
  </code></pre>
  
  <p>where <code>in</code> is the input file.</p>