title: Java―MalformedInputException with BufferedReader
body: <p>I am a bit new to Java, so I have absolutely no Idea how to fix the following Problem. I am coding a small cli program to processes mysql-dump-files. In the (hopefully) last Junit-test a »bigger« (990.3kB) Mysql-file is processed and only this file gives this error:</p>
  
  <pre><code>java.nio.charset.MalformedInputException: Input length = 1
  </code></pre>
  
  <p>Neither the error message no the description from the <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/charset/MalformedInputException.html" rel="nofollow noreferrer">docs</a> give my a hint hot to fix it. If I open the file with Kate this error is shown:</p>
  
  <p><img src="https://i.stack.imgur.com/f9oDW.png" alt="screenshot of the error-message from kate"></p>
  
  <p>Right now the code* looks like:</p>
  
  <pre><code>String line;
  BufferedReader reader = Files.newBufferedReader(in, Charset.forName( "UTF-8" ) );
  
  while( ( line = reader.readLine() ) != null )
  {
     //processing stuff goes here
  }
  </code></pre>
  
  <p>*calling <code>reader.readLine()</code> is what causes the error.</p>
  
  <p>I guess I need to change to way how to read the file, but that is just guessing and hope for some good help here. If anybody has a Link to a resource which gives some background Information for this would be very fine, too.</p>
  
  <p>Thanks in ahead!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After some searching I could manage to make Java »read that file« by changing the above code to:</p>
  
  <pre><code>BufferedReader reader = 
      new BufferedReader( 
          new InputStreamReader( 
              new FileInputStream( in.toFile() ) ) );
  </code></pre>
  
  <p>Is this the way to work around potential charset problems? Will this lead me to other potential issues? I would really appreciate some explanation about the details… </p>