title: Files.readAllBytes vs Files.lines getting MalformedInputException
body: <p>I would have thought that the following two approaches to read a file should behave equally. But they don't. The second approach is throwing a <code>MalformedInputException</code>.</p>
  
  <pre><code>public static void main(String[] args) {    
      try {
          String content = new String(Files.readAllBytes(Paths.get("_template.txt")));
          System.out.println(content);
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      try(Stream&lt;String&gt; lines = Files.lines(Paths.get("_template.txt"))) {
          lines.forEach(System.out::println);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>This is the stack trace:</p>
  
  <pre><code>Exception in thread "main" java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
      at java.io.BufferedReader$1.hasNext(BufferedReader.java:574)
      at java.util.Iterator.forEachRemaining(Iterator.java:115)
      at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
      at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
      at Test.main(Test.java:19)
  Caused by: java.nio.charset.MalformedInputException: Input length = 1
      at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
      at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
      at java.io.InputStreamReader.read(InputStreamReader.java:184)
      at java.io.BufferedReader.fill(BufferedReader.java:161)
      at java.io.BufferedReader.readLine(BufferedReader.java:324)
      at java.io.BufferedReader.readLine(BufferedReader.java:389)
      at java.io.BufferedReader$1.hasNext(BufferedReader.java:571)
      ... 4 more
  </code></pre>
  
  <p>What is the difference here, and how do I fix it?</p>