title: Java 8 - java.nio.charset.MalformedInputException
body: <p>I am getting reading a file through java-8 and finding a match for a key in that file using the below method:</p>
  
  <pre><code>private static List&lt;String&gt; listFilesWithMatches(String[] listOfIncludedFiles, Map&lt;String, String&gt; myPropMapKeys) {
  
      List&lt;String&gt; mapKeyList = new ArrayList&lt;String&gt;(myPropMapKeys.keySet());
      List&lt;String&gt; matchFileList = new ArrayList&lt;&gt;();
      Predicate&lt;String&gt; p = (str) -&gt; mapKeyList.stream().anyMatch(key -&gt; str.contains(utf8AsLatin1(key)));
  
  
  
      for(String myFile : listOfIncludedFiles){
           try (Stream&lt;String&gt; stream = Files.lines(Paths.get(myFile))) {
               boolean foundAKey = stream.anyMatch(p);
                  if(foundAKey) {
                      matchFileList.add(myFile);
  
                      //Listing the files that have match
                      System.out.println("**"+ROOT_PATH + File.separator + myFile);
                  }
           }
  
           catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
      System.out.println("Total Number of files with matches:: "+matchFileList.size());
      return matchFileList;
  }
  
  private static String utf8AsLatin1(String key) {
       return new String(key.getBytes(StandardCharsets.ISO_8859_1),
               StandardCharsets.UTF_8);
  }
  </code></pre>
  
  <p>now i am getting the below error </p>
  
  <pre><code>Exception in thread "main" java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
      at java.io.BufferedReader$1.hasNext(Unknown Source)
      at java.util.Spliterators$IteratorSpliterator.tryAdvance(Unknown Source)
      at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
      at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
      at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
      at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
      at java.util.stream.MatchOps$MatchOp.evaluateSequential(Unknown Source)
  </code></pre>
  
  <p>The line that is creating the problem is </p>
  
  <pre><code>try (Stream&lt;String&gt; stream = Files.lines(Paths.get(myFile))) {
                   boolean foundAKey = stream.anyMatch(p);
  </code></pre>
  
  <p>Now one of the solution is to use the ISO_8859_1 charset but i want the default encoding of the file only and don't want to use any other charset. Can anybody help with this issue?</p>