title: Java BufferedReader reads an empty txt file but doesn't return null
body: <p>I tried to use a Java BufferedReader to read an empty txt file.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    File recentFile = new File(path);
      try {
              BufferedReader reader = new BufferedReader(newInputStreamReader(newFileInputStream(recentFile), "UTF-8"));
              String temp = reader.readLine();
              reader.close();
              if (temp == null) {System.out.println("your file is empty");}
              else {System.out.println(temp);}
      } catch (IOException ex) {}
  </code></pre>
  
  <p>The txt file is completely empty, but when I run the program, The command prompt prints out "?" instead of "your file is empty".</p>
  
  <p>When I change "UTF-8" to "Unicode", and change my txt file encoding format to Unicode, I get a "your file is empty" from the prompt.</p>
  
  <p>Why do I get this result when I use UTF-8?</p>
  
  <p>btw, if this is a duplicate please let me know, I tried to search this multiple times on google but couldn't find anything helpful to me.</p>