title: How to preserve newlines while reading a file using stream - java 8
body: <pre><code>      try (Stream&lt;String&gt; lines = Files.lines(targetFile)) {  
       List&lt;String&gt; replacedContent = lines.map(line -&gt;  
                                         StringUtils.replaceEach(line,keys, values))
                                         .parallel()
                                         .collect(Collectors.toList());
      Files.write(targetFile, replacedContent);
  }
  </code></pre>
  
  <p>I'm trying to replace multiple text patterns in each line of the file. But I'm observing that "\r\n"(byte equivalent 10 and 13) is being replaced with just "\r"(just 10) and my comparison tests are failing. </p>
  
  <p>I want to preserve the newlines as they are in the input file and don't want java to touch them. Could anyone suggest if there is a way to do this without having to use a separate default replacement for "\r\n". </p>