FileReader is a character stream reading character by character from a file. Note: Before reading this tutorial, it is advised to know Java I/O Streams – Overview. FileReader is equivalent to FileInputStream of byte streams. The following example reads character by character from file wishes.txt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import java.io.*; public class FRDemo { public static void main(String args[]) throws IOException { FileReader fr = new FileReader("wishes.txt"); int temp; while((temp = fr.read()) != -1) { System.out.print((char)temp); } fr.close(); } } |
Output Screenshot on FileReader Java…