Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.io.FileReader; public class Main { public static void main(String[] args) { try { FileReader fr = new FileReader("Javafile.txt"); int data = fr.read(); while (data != -1) { System.out.print((char) data); data = fr.read(); } fr.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } |
FileReader class inherits from the InputStreamReader class. FileReader is used for reading streams of characters.