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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.