I tried to use a Java BufferedReader to read an empty txt file.
Here's my 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) {}
The txt file is completely empty, but when I run the program, The command prompt prints out "?" instead of "your file is empty".
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.
Why do I get this result when I use UTF-8?
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.