title: java.lang.OutOfMemoryError while reading file to byte[] array
body: <p>Is there a cleaner and faster way to do this:</p>
  
  <pre><code>BufferedReader inputReader = new BufferedReader(new InputStreamReader(context.openFileInput("data.txt")));
  String inputString;
  StringBuilder stringBuffer = new StringBuilder();
  while ((inputString = inputReader.readLine()) != null) {
      stringBuffer.append(inputString + "\n");
  }
  text = stringBuffer.toString();
  byte[] data = text.getBytes();
  </code></pre>
  
  <p>Basically I'm trying to convert a file into <code>byte[]</code>, except if the file is large enough then I run into an outofmemory error. I've been looking around <a href="https://stackoverflow.com/questions/9505025/byte-and-java-lang-outofmemoryerror-reading-file-by-bits">SO</a> for a solution, I tried to do this here, and it didn't work. Any help would be appreciated.</p>