Java Scanner(InputStream source) Constructor

Syntax

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

public Scanner(InputStream source)

Example

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


import java.io.FileInputStream;
import java.util.Scanner;
//from  w  ww . j a  v a2s.c o  m
public class Main {

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

      scanner.close();
   }
}