title: Reading and writing huge files in java
body: <p>My idea is to make a little software that reads a file (which can't be read "naturally", but it contains some images), turns its data into hex, looks for the PNG chunks (a kind of marks that are at the beginning and end of a .png file), and saves the resulting data in different files (after getting it back from hex). I am doing this in Java, using a code like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>// out is where to show the result and file is the source
  public static void hexDump(PrintStream out, File file) throws IOException {
      InputStream is = new FileInputStream(file);
      StringBuffer Buffer = new StringBuffer();
  
      while (is.available() &gt; 0) {
          StringBuilder sb1 = new StringBuilder();
  
          for (int j = 0; j &lt; 16; j++) {
              if (is.available() &gt; 0) {
                  int value = (int) is.read();
                  // transform the current data into hex
                  sb1.append(String.format("%02X ", value));
              }
          }
  
          Buffer.append(sb1);
  
          // Should I look for the PNG here? I'm not sure
      }
      is.close();
      // Print the result in out (that may be the console or a file)
      out.print(Buffer);
  
  }
  </code></pre>
  
  <p>I'm sure there are another ways to do this using less "machine-resources" while opening huge files. If you have any idea, please tell me. Thanks!</p>
  
  <p>This is the first time I post, so if there is any error, please help me to correct it.</p>