title: Java Reading large files into byte array chunk by chunk
body: <p>So I've been trying to make a small program that inputs a file into a byte array, then it will turn that byte array into hex, then binary. It will then play with the binary values (I haven't thought of what to do when I get to this stage) and then save it as a custom file.</p>
  
  <p>I studied a lot of internet code and I can turn a file into a byte array and into hex, but the problem is I can't turn huge files into byte arrays (out of memory).</p>
  
  <p>This is the code that is not a complete failure</p>
  
  <pre><code>public void rundis(Path pp) {
      byte bb[] = null;
  
      try {
          bb = Files.readAllBytes(pp); //Files.toByteArray(pathhold);
          System.out.println("byte array made");
      } catch (Exception e) {
          e.printStackTrace();
      }
      if (bb.length != 0 || bb != null) {
          System.out.println("byte array filled");
          //send to method to turn into hex
      } else {
          System.out.println("byte array NOT filled");
      }
  
  }
  </code></pre>
  
  <p>I know how the process should go, but I don't know how to code that properly.</p>
  
  <p>The process if you are interested:</p>
  
  <ul>
  <li>Input file using <code>File</code></li>
  <li>Read the chunk by chunk of the file into a byte array. Ex. each byte array record hold 600 bytes</li>
  <li>Send that chunk to be turned into a Hex value --> <code>Integer.tohexstring</code></li>
  <li>Send that hex value chunk to be made into a binary value --> <code>Integer.toBinarystring</code></li>
  <li>Mess around with the Binary value</li>
  <li>Save to custom file line by line</li>
  </ul>
  
  <p><strong>Problem</strong>:: I don't know how to turn a huge file into a byte array chunk by chunk to be processed.
  Any and all help will be appreciated, thank you for reading :)</p>