• Profile
  • Resume
  • Portfolio
  • Blog
Avatar

Nelson Silva

A human. Being. Coffee lover.

Blog

I Write My Thoughts Here

FileReader Class in Java

April 1, 2022 Java

In this post, you will learn how to work with the FileReader class so that you can use that same knowledge and thus evolve.

  • this class implements a reading mode so that one can read the characters present in a stream (file) according to a specific encoding.
FileReader (object).read() Reads the entire content of the file to the end
FileReader (object).close() Terminates existing link with the given file
package com.caffeinealgorithm.programminginjava;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class FileReaderClass {
  private File file = new File("File.txt");
  private char[] characters = new char[100];
  private FileReader readFile;

  public void Run() {
    if (file.exists()) {
      try {
        readFile = new FileReader(file);
        readFile.read(characters);

        for (char character : characters)
          System.out.print(character);

        readFile.close();
      }
      catch (IOException exception) {
        System.out.println(exception);
      }
    }
  }
}

/*
  Portugal
  Brazil
  Spain
  France
  Italy
  Australia
  India
*/

Don’t forget to watch the video and you can always read this post in Portuguese.

Happy coding!

Previous Next

Categories

  • Announcements
  • Python
  • C#
  • Java
  • Go

Latest Posts

  • for Loop in Go
    May 5, 2022
  • Switch in Go
    May 4, 2022
  • Comparison Operators in Go
    May 3, 2022
+351913416022
contact@nelsonsilvadev.com
Porto, Portugal
Nelson Silva © 2022 All Rights Reserved