Example usage for java.util Scanner close

List of usage examples for java.util Scanner close

Introduction

In this page you can find the example usage for java.util Scanner close.

Prototype

public void close() 

Source Link

Document

Closes this scanner.

Usage

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 true ";

    Scanner scanner = new Scanner(s);

    System.out.println(scanner.nextLine());

    // print the default radix
    System.out.println(scanner.radix());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 true ";

    Scanner scanner = new Scanner(s);

    System.out.println(scanner.nextLine());

    // attempt to call remove results in an exception
    scanner.remove();/*w w w  .  j a va2  s .co m*/

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(FileSystems.getDefault().getPath("logs", "access.log"),
            StandardCharsets.UTF_8.name());
    System.out.println(scanner.nextLine());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 true ";

    Scanner scanner = new Scanner(s);

    // skip the word that matches the pattern .com
    scanner.skip(Pattern.compile(".com"));

    System.out.println(scanner.nextLine());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 ";

    Scanner scanner = new Scanner(s);

    // print the line
    System.out.println(scanner.nextLine());

    // print the current locale
    System.out.println(scanner.locale());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com \n 1 + 1 = 2.0 true ";

    Scanner scanner = new Scanner(s);

    // print the next line
    System.out.println(scanner.nextLine());

    // print the next line again
    System.out.println(scanner.nextLine());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(new File("fileName"));
    scanner.useDelimiter(System.getProperty("line.separator"));
    while (scanner.hasNext()) {
        parseLine(scanner.next());//w  ww.  java 2s.co  m
    }
    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 ";

    Scanner scanner = new Scanner(s);

    // print the line
    System.out.println(scanner.nextLine());

    // check if there is an IO exception
    System.out.println(scanner.ioException());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0";

    Scanner scanner = new Scanner(s);

    // find a string "com"
    System.out.println(scanner.findInLine("com"));

    // print the rest of the string
    System.out.println(scanner.nextLine());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 ";

    Scanner scanner = new Scanner(s);

    // find the next token and print it
    System.out.println(scanner.next());

    // find the next token and print it
    System.out.println(scanner.next());

    scanner.close();
}