Read text from character input stream FileReader class

import java. io. FileReader; import java. io. IOException; /* * The character input stream reads text files (only text files can be read). The superclass Java. Io. Reader * of all character input streams reads: read(): * int read(): reads a character * int read (char [] C): reads a character array * the reader class is an abstract class, Find its subclass object FileReader * / public class readerdemo {public static void main (string [] args) throws IOException {FileReader fr = new FileReader ("D: \ \ demo \ \ b.txt"); / / method 1 / * int len = 0; while ((len = fr.read())! = - 1) {system. Out. Print NT ((char) LEN);} * /// Method 2: char [] ch = new char [1024]; int len=0; while((len=fr.read())!=- 1){ System.out.println(new String(ch,len)); } fr.close(); }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>