Java Scanner(InputStream source, String charsetName) Constructor

Syntax

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

public Scanner(InputStream source,   String charsetName)

Example

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


import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
//from   ww  w.ja  va 2s  .  c  om
public class Main {

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

      scanner.close();
   }
}