FileReader Class

How to use Java FileReader Class FileReader is character-oriented class which is used for file handling in Java. It is meant for reading streams of characters. One character may correspond to one or more bytes depending on the character encoding scheme .
FileReader fileReader = new FileReader(filename);

Character Encoding

Java FileReader Class Character Encoding This Class assumes that you want to decode the bytes in the file using the default character encoding for the program is running on. This may not always be what you want, and you cannot change it. So, if you want to specify a different character decoding scheme , try to avoid this class. InputStreamReader is the better option, since FileReader extends InputStreamReader, FileReader uses character encoding provided to this class, or else use default character encoding of platform. Remember, InputStreamReader caches the character encoding and setting character encoding after creating object will not have any affect. Example
import java.util.*; import*; public class TestClass{ public static void main(String[] args) { try { FileReader fileReader = new FileReader("D:\\test.txt"); int chr =; while(chr != -1) { System.out.print((char) chr); chr =; } } catch (IOException e){ e.printStackTrace(); } } }