title: How to convert binary text into useable file
body: <p>So I use the following methods </p>
  
  <p>(File is converted to Byte Array through 'convertFileToByteArray()', then written to .txt file by 'convertByteArrayToBitTextFile()'</p>
  
  <p>to convert any kind of file into a Binary Text file (and by that I mean only 1's and 0's in human readable form.)</p>
  
  <pre><code>public static byte[] convertFileToByteArray(String path) throws IOException
  {
      File file = new File(path);
      byte[] fileData;
      fileData = new byte[(int)file.length()];
      FileInputStream in = new FileInputStream(file);
      in.read(fileData);
      in.close();
      return fileData;
  }
  
  public static boolean convertByteArrayToBitTextFile(String path, byte[] bytes)
  {
      String content = convertByteArrayToBitString(bytes);
      try
      {
          PrintWriter out = new PrintWriter(path);
          out.println(content);
          out.close();
          return true;
      }
      catch (FileNotFoundException e)
      {
          return false;
      }
  }
  
  public static String convertByteArrayToBitString(byte[] bytes)
  {
      String content = "";
      for (int i = 0; i &lt; bytes.length; i++)
      {
          content += String.format("%8s", Integer.toBinaryString(bytes[i] &amp; 0xFF)).replace(' ', '0');
      }
      return content;
  }
  </code></pre>
  
  <p><strong>Edit:</strong> Additional Code:</p>
  
  <pre><code>public static byte[] convertFileToByteArray(String path) throws IOException
  {
      File file = new File(path);
      byte[] fileData;
      fileData = new byte[(int)file.length()];
      FileInputStream in = new FileInputStream(file);
      in.read(fileData);
      in.close();
      return fileData;
  }
  
  public static boolean convertByteArrayToBitTextFile(String path, byte[] bytes)
  {
      try
      {
          PrintWriter out = new PrintWriter(path);
          for (int i = 0; i &lt; bytes.length; i++)
          {
              out.print(String.format("%8s", Integer.toBinaryString(bytes[i] &amp; 0xFF)).replace(' ', '0'));
          }
          out.close();
          return true;
      }
      catch (FileNotFoundException e)
      {
          return false;
      }
  }
  
  public static boolean convertByteArrayToByteTextFile(String path, byte[] bytes)
  {
      try
      {
          PrintWriter out = new PrintWriter(path);
          for(int i = 0; i &lt; bytes.length; i++)
          {
              out.print(bytes[i]);
          }
          out.close();
          return true;
      }
      catch (FileNotFoundException e)
      {
          return false;
      }
  }
  
  public static boolean convertByteArrayToRegularFile(String path, byte[] bytes)
  {
      try
      {
          PrintWriter out = new PrintWriter(path);
          for(int i = 0; i &lt; bytes.length; i++)
          {
              out.write(bytes[i]);
          }
          out.close();
          return true;
      }
      catch (FileNotFoundException e)
      {
          return false;
      }
  }
  
  public static boolean convertBitFileToByteTextFile(String path) 
  {
      try
      {
          byte[] b = convertFileToByteArray(path);
          convertByteArrayToByteTextFile(path, b);
          return true;
      }
      catch (IOException e)
      {
          return false;
      }
  
  }
  </code></pre>
  
  <p>I do this to try methods of compression on a very fundamental level, so please let's not discuss why use human-readable form.</p>
  
  <p>Now this works quite well so far, however I got two problems.</p>
  
  <p>1) 
  It takes foreeeever (>20 Minutes for 230KB into binary text). Is this just a by-product of the relatively complicated conversion or are there other methods to do this faster?</p>
  
  <p>2) <strong>and main problem:</strong>
  I have no idea how to convert the files back to what they used to be. Renaming from .txt to .exe does not work (not too surprising as the resulting file is two times larger than the original) </p>
  
  <p>Is this still possible or did I lose Information about what the file is supposed to represent by converting it to a human-readable text file?
  If so, do you know any alternative that prevents this?</p>
  
  <p>Any help is appreciated.</p>