title: Java avoid java.lang.OutOfMemoryError while reading a file but using streams at the same time
body: <p>I'm trying to read a very large file with streams so I need parallel streams and not iterations per line... I'm trying as follows:</p>
  
  <pre><code>String cont = new String(Files.readAllBytes(Paths.get(this.File_Path)),
              StandardCharsets.UTF_8);    
  List&lt;String&gt; words = Arrays.asList(cont.split("\\PL+"));
  
  yep = words.parallelStream()
              .filter(x -&gt; x.contains(toMatch))
              .distinct()
              .collect(Collectors.toList());
  </code></pre>
  
  <p>This works for small file size, but if I try to make the same with a file that has some gbs of size java gives me this exception:</p>
  
  <pre><code>java.lang.OutOfMemoryError: Required array size too large
  </code></pre>
  
  <p>There is a way to avoid this exception but using parallel stream at the same time instead of iterate with BufferReader or Scanner?</p>