Java FileReader Class getEncoding() Method with Examples Last Updated : 02 Feb, 2022 Comments Improve Suggest changes Like Article Like Report The getEncoding() method of FileReader Class in Java is used to return the name of the current stream's character encoding. If the stream is utilizing a historical encoding name, it will be returned; otherwise, the canonical encoding name of the stream will be returned. Syntax: public String getEncoding() Returns: This method returns the encoding's historical name, or null if the stream has been closed. Example: We generated two file readers, input1 and input2, in the preceding example. The character encoding is not specified in input1. As a result, the default character encoding is returned by the getEncoding() function. The character encoding, UTF8, is specified by input2. As a result, the getEncoding() function returns the character encoding supplied. Java // Java Program to demonstrate the working of // getEncoding() Method of FileReader Class import java.io.FileReader; import java.nio.charset.Charset; class GFG { public static void main(String[] args) { try { // Creates a FileReader with the encoding set to // default. FileReader input1 = new FileReader( "C:\\Users\\lenovo\\Desktop\\input.txt"); // Creates a FileReader with the specified // encoding. FileReader input2 = new FileReader( "C:\\Users\\lenovo\\Desktop\\input.txt", Charset.forName("UTF8")); // The file reader's character encoding is // returned. System.out.println( "Character encoding of input1: " + input1.getEncoding()); System.out.println( "Character encoding of input2: " + input2.getEncoding()); // Closing Reader input1.close(); input2.close(); } catch (Exception e) { e.getStackTrace(); } } } Assume we have a text file named input.txt that contains the following information. This file will be utilized as a source of data in our example application. GEEKSFORGEEKS Output: Comment More infoAdvertise with us Next Article Java FileReader Class getEncoding() Method with Examples S sanketnagare Follow Improve Article Tags : Java Java-Functions java-file-handling Practice Tags : Java Similar Reads Java FileReader Class read() Method with Examples The read() method of FileReader class in Java is used to read and return a single character in the form of an integer value that contains the character's char value. The character read as an integer in the range of 0 to 65535 is returned by this function. If it returns -1 as an int number, it means 2 min read Java FileReader Class ready() Method with Examples Java FileReader class is used to read data from the data file. It returns the data in byte format as FileInputStream class. This is a character-oriented class that is used for file handling in Java. ready() Method of FileReader Class It checks if the file reader is ready to be read. It will return a 3 min read Class getEnclosingClass() method in Java with Examples The getEnclosingClass() method of java.lang.Class class is used to get the enclosing class of this class. The method returns the enclosing class of this class, if this class is a local class or anonymous class declared in that class. Else this method returns null.Syntax: public Class getEnclosingCla 2 min read Class getEnclosingMethod() method in Java with Examples The getEnclosingMethod() method of java.lang.Class class is used to get the enclosing methods of this class. The method returns the enclosing methods of this class if this class is a local class or anonymous class declared in that method. Else this method returns null.Syntax: public Method getEnclos 2 min read Class getModifiers() method in Java with Examples The getModifiers() method of java.lang.Class class is used to get the Java language modifiers of this class. The method returns an integer representing the encoded modifiers of this class. Syntax: public int getModifiers() Parameter: This method does not accept any parameter.Return Value: This metho 2 min read Charset forName() method in Java with Examples The forName() method is a built-in method of the java.nio.charset returns a charset object for the named charset. In this function we pass a canonical name or an alias and its respective charset name is returned. Syntax: public static Charset forName?(String charsetName) Parameters: The function acc 3 min read File canRead() method in Java with Examples The canRead()function is a part of the File class in Java. This function determines whether the program can read the file denoted by the abstract pathname. The function returns true if the abstract file path exists and the application is allowed to read the file.Function signature: public boolean ca 2 min read Class getEnclosingConstructor() method in Java with Examples The getEnclosingConstructor() method of java.lang.Class class is used to get the enclosing constructors of this class. The method returns the enclosing constructors of this class, if this class is a local class or anonymous class declared in that constructor. Else this method returns null.Syntax: pu 2 min read FileInputStream available() Method in Java with Examples The available() method of FileInputStream class is used to return the estimated number of remaining bytes that can be read from the input stream without blocking. This method returns the number of bytes remaining to read from the file. When a file is completely read, this function returns zero. Synt 3 min read CharsetDecoder isAutoDetecting() method in Java with Examples The isAutoDetecting() method is a built-in method of the java.nio.charset.CharsetDecoder class which tells whether or not this decoder implements an auto-detecting charset. Syntax: public boolean isAutoDetecting() Parameters: The function does not accepts any parameter. Return Value: The function re 1 min read Like