title: Java - Incorrect Reader
body: <p>I´m trying to read a txt file that contains special characters, but some of those characters are read as squares. </p>
  
  <p>Here the code.</p>
  
  <pre><code>package reader;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileReader;
  import java.io.IOException;
  
  public class Reader {
      public static void main(String[] args) throws IOException {
          File file = new File("cfg.txt");
          BufferedReader reader = new BufferedReader(new FileReader(file));
          String line;
          while( (line=reader.readLine()) != null ){
              System.out.println(line);
          }
      }
  }
  </code></pre>
  
  <p>The file:</p>
  
  <pre><code>ÉCltTctocsWicÉ#V^ÊûJö=
  </code></pre>
  
  <p>The console output:</p>
  
  <pre><code>�CltTctocsWic�#V^��J�=
  </code></pre>
  
  <p>The project is using UTF-8. Already tried FileInputStream with same result.</p>
  
  <p>Do i need another reader?</p>
  
  <p><strong>EDIT:Solved</strong></p>
  
  <p>Thanks to @shmosel, the text file wasn't in UTF-8.<br>
  Thanks to @ACV, the InputStreamReader was necessary.</p>
  
  <p>Here the new code:</p>
  
  <pre><code>public class Reader {
      public static void main(String[] args) throws IOException {
          File file = new File("cfg.txt");
  
          /*to write*/
          BufferedWriter ou = new BufferedWriter(
                  new OutputStreamWriter(
                          new FileOutputStream(file),"UTF8"));
          ou.append("ÉCltTctocsWicÉ#V^ÊûJö=");
          ou.close();
  
          /*to read*/
          BufferedReader in = new BufferedReader(
             new InputStreamReader(
                    new FileInputStream(file), "UTF8"));
          String line;
          while( (line=in.readLine()) != null ){
              System.out.println(line);
          }
      }
  }
  </code></pre>