FileReader -Java Read File Line by Line in Java

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] + " ");

Post a Comment

Thank you for vising

Previous Post Next Post