Can I peek on a BufferedReader?

后端 未结 8 1859
别跟我提以往
别跟我提以往 2021-01-01 14:02

Is there a way to check if in BufferedReader object is something to read? Something like C++ cin.peek(). Thanks.

8条回答
  •  误落风尘
    2021-01-01 14:32

    You can try the "boolean ready()" method. From the Java 6 API doc: "A buffered character stream is ready if the buffer is not empty, or if the underlying character stream is ready."

    BufferedReader r = new BufferedReader(reader);
    if(r.ready())
    {
       r.read();
    }
    

提交回复
热议问题