Java Scanner(ReadableByteChannel source, String charsetName) Constructor

Syntax

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

public Scanner(ReadableByteChannel source,   String charsetName)

Example

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


/*from w ww.  j  av a2 s.c om*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Main {

   public static void main(String[] args) throws FileNotFoundException {

      Scanner scanner = new Scanner(new FileInputStream("c:/text.txt").getChannel(),StandardCharsets.UTF_8.name());


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

      // change the radix of the scanner
      scanner.useRadix(32);

      // display the new radix
      System.out.println(scanner.radix());

      scanner.close();
   }
}