Java Scanner(Path source) Constructor

Syntax

Scanner(Path source) constructor from Scanner has the following syntax.

public Scanner(Path source)  throws IOException

Example

In the following code shows how to use Scanner.Scanner(Path source) constructor.


import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.util.Scanner;
/*w  w  w .j  ava  2 s .  c o m*/
public class Main {

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

      scanner.close();
   }
}