Java Scanner(File source) Constructor

Syntax

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

public Scanner(File source)  throws FileNotFoundException

Example

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


import java.io.File;
import java.util.Scanner;
//from  w w w .j  av a  2s.co m
public class Main {

   public static void main(String[] args) throws Exception {
      Scanner scanner = new Scanner(new File("c:/text.txt"));
      System.out.println(scanner.nextLine());

      scanner.close();
   }
}