InputStreamReader getEncoding Example
InputStreamReader class getEncoding example. This example shows you how to use getEncoding method.
InputStreamReader class getEncoding example.public String getEncoding() Returns the name of the character encoding being used by this stream. If the encoding has an historical name then that name is returned; otherwise the encoding's canonical name is returned.
Here is the code
/**
* @ # getEncoding.java
* A class repersenting use to getEncoding method
* of InputStreamReader class in java.io package
* version 28 May 2008
* author Rose India
*/
import java.io.*;
public class GetEncoding {
public static void main(String args[]) throws Exception {
File file = new File("text.txt");
if (!file.exists()) {
System.out.println("File not found");
System.exit(1);
}
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis);
// Returns the name of the character encoding
System.out.println("Name of the character encoding "+isr.getEncoding());
//Closes the stream
isr.close();
}
} |
Output
| Name of the character encoding UTF8 |
|