title: Converting String of 1's and 0's to a binary file
body: <p>So I have a String of thousands of 1's and 0's that I want to save to a file as binary (so that file size is small). Unfortunately I cannot figure out how to do it without running into NumberFormatExceptions. </p>
  
  <p>I've tried Byte.parseByte but that doesn't seem to work. Any help would be greatly appreciated. </p>
  
  <pre><code> try {
          File file = new File(BINARY_FILE);
          DataOutputStream dso = new DataOutputStream(new FileOutputStream(file));
          for (int j = 0; j &lt; bits.length(); j += 8) {
              Byte b = Byte.parseByte(bits.substring(j, j + 8));
              dso.write(b);
          }
      } catch (IOException e) {
          System.out.println("Error");
      }
  </code></pre>