Hello every body
i have a problem with Scanner class.So my question is that when we use BufferedReader orInputStreamReader to reading and writing input and output then we use close()method to close the stream but in the case of Scanner why we do not close the stream this is my question

and second question is that difference between flush() and close() methods

Edited by moaz.amin.37

3 Years
Discussion Span
Last Post by JamesCherrill

You can close() a Scanner, but if you are using System.in then the close() has no effect (System.in cannot be closed), so people don't bother.
flush() writes any buffered output to the underlying device and allows you to continue writing to it. close() writes any buffered output to the udnerlying device then closes it so you cannot write to it any more.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.