Java IO Tutorial - Java InputStreamReader .getEncoding ()








Syntax

InputStreamReader.getEncoding() has the following syntax.

public String getEncoding()

Example

In the following code shows how to use InputStreamReader.getEncoding() method.

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
/*  ww w .  j av a  2  s. com*/
public class Main {
  public static void main(String[] args) throws IOException {
    // new input stream reader is created
    FileInputStream fis = new FileInputStream("C:/test.txt");
    InputStreamReader isr = new InputStreamReader(fis);

    // the name of the character encoding returned
    String s = isr.getEncoding();
    System.out.print("Character Encoding: " + s);
    isr.close();
  }
}