FileReader -Java Read File Line by Line in Java

Posted By: Java Examples - 7:56 PM


& Comment

The FileReader class makes it possible to read the contents of a file as a stream of characters. It works much like the FileInputStream except the FileInputStream reads bytes, whereas the FileReader reads characters. The FileReader is intended to read text, in other words. One character may correspond to one or more bytes depending on the character encoding scheme.
Java version of Example :
public void readFile() throws IOException {
  Scanner filescan = new Scanner(new FileReader("input.txt"));
  int i = 0;
  while (filescan.hasNext() && i < size) {
   array[i] = filescan.nextInt();
  System.out.println("The Array of Element are :");
  for (int j = 0; j < size; j++) {
   System.out.print(array[j] + " ");

About Java Examples

I’m passionate about Web Development and Programming and I go to extreme efforts to meet my passion. I’m a believer of learning the fundamentals first. I try to understand everything little bit more than the average.


Post a Comment

Thank you for vising

Copyright © 2016 Java Examples ACHCHUTHAN.ORG. Designed by Templateism .