Scanner close() method in Java with Examples Last Updated : 10 Oct, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The close() method ofjava.util.Scanner class closes the scanner which has been opened. If the scanner is already closed then on calling this method, it will have no effect. Syntax: public void close() Return Value: The function does not return any value. Below programs illustrate the above function: Program 1: Java // Java program to illustrate the // close() method of Scanner class in Java import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // Get the string String s = "Geeksforgeeks has Scanner Class Methods"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print the next line of the string System.out.println("Scanner: " + scanner.nextLine()); // close the scanner scanner.close(); System.out.println("\nScanner Closed.\n"); System.out.println("Trying to use scanner" + " after closing."); // print the next line of the string System.out.println(scanner.nextLine()); } catch (Exception e) { System.out.println("Exception thrown:\n" + e); } } } Output: Scanner: Geeksforgeeks has Scanner Class Methods Scanner Closed. Trying to use scanner after closing. Exception thrown: java.lang.IllegalStateException: Scanner closed Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#close() Comment More infoAdvertise with us Next Article Scanner close() method in Java with Examples G gopaldave Follow Improve Article Tags : Java Java - util package Java-I/O Java-Functions Practice Tags : Java Similar Reads Reader close() method in Java with Examples The close() method of Reader Class in Java is used to close the stream and release the resources that were busy in the stream, if any. This method has following results: If the stream is open, it closes the stream releasing the resources If the stream is already closed, it will have no effect. If an 2 min read Scanner delimiter() method in Java with Examples The delimiter() method ofjava.util.Scanner class returns the Pattern this Scanner is currently using to match delimiters. Syntax: public Pattern delimiter() Return Value: The function returns the scanner's delimiting pattern. Below programs illustrate the above function: Program 1: Java // Java prog 2 min read Scanner skip() method in Java with Examples skip(Pattern pattern) The skip(Pattern pattern) method of java.util.Scanner class skips input that matches the specified pattern, ignoring the delimiters. The function skips the input if an anchored match of the specified pattern succeeds it. Syntax: public Scanner skip(Pattern pattern) Parameters: 5 min read Console reader() method in Java with Examples The reader() method of Console class in Java is used to retrieve the unique Reader object which is associated with the console. This reader() method is generally used by sophisticated applications. Simple applications that require only line oriented reading, normally use readLine() method instead of 2 min read Scanner reset() method in Java with Examples The reset() method of java.util.Scanner class resets this scanner. On resetting a scanner, it discards all of its explicit state information which may have been changed by invocations of useDelimiter(java.util.regex.Pattern), useLocale(java.util.Locale), or useRadix(int). Syntax: public Scanner rese 2 min read Like