FileReader Class in 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.