br.read() 如何在读取字符串结束时给出 -1 或 br.read() 究竟如何工作?

How is br.read() giving out -1 at the end of reading the string or How exactly does the br.read() works?

这是一个示例程序,作为缓冲 reader 的示例,我了解了其中的大部分内容并理解了 while 循环执行在 (br.read()=-1) 时停止的事实,但不明白为什么会这样那么?

import java.io.*;  
public class BufferedReaderExample {  
    public static void main(String args[])throws Exception{    
          FileReader fr=new FileReader("D:\testout.txt");    
          BufferedReader br=new BufferedReader(fr);    
  
          int i;    
          while((i=br.read())!=-1)    //<<<<I'm talking about this here
          {  
          System.out.print((char)i);  
          }  
          br.close();    
          fr.close();    
    }    
} 

-1 是一个超出方法 return 值正常范围的信号值。它用于表示已到达流结尾:

Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached

(from: BufferedReader.read())

简而言之,正如 Federico klez Culloca 在评论中提到的那样,原因是 read() 就是这样设计的。