import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
//This class inherits from the InputStreamReader class. FileReader is used for reading
//streams of characters.
//FileReader(File file)
//FileReader(FileDescriptor fd)
//FileReader(String fileName)
//Methods with Description
//public int read() throws IOException
//Reads a single character. Returns an int, which represents the character read.
//public int read(char [] c, int offset, int len)
//Reads characters into an array. Returns the number of characters read.
public class FileReaderClassDemo {
public static void main(String[] args) throws IOException {
File file = new File("test.txt");
file.createNewFile();
FileWriter fWriter = new FileWriter(file);
fWriter.write("This is \n the text \n to display");
fWriter.flush();
fWriter.close();
FileReader fReader = new FileReader(file);
char a[] = new char[50];
fReader.read(a);
for (char c : a) {
System.out.print(c);
}
fReader.close();
}
}

No comments:
Post a Comment