title: What is the best way to convert a string of 0's and 1's into byte[] in java
body: <p>My program should get a path for a text file as input.
  The text is just 1's and 0's and the program needs to read it as bytes.
  This is what I got so far, it's working but I know there's a better way</p>
  
  <pre><code>public void transform(String input_File)
  {
      File file = new File(input_file);
  
      BufferedReader br = null;
      try {
          br = new BufferedReader(new FileReader(file));
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      String org_text = null;
      String byte_val;
      try {
          while ((org_text = br.readLine()) != null)
          {
              for (int i = 0; i &lt; org_text.length();i += 8)
              {
                  byte_val = org_text.substring(i, i+8);
                  int ch = Integer.parseInt(byte_val, 2);
                  //some more lines here, but it dosn't matter
  
              }
  
          }
      } catch (IOException e)
      {
          e.printStackTrace();
      }
  </code></pre>