1 Packagefile operation;2 3 ImportJava.io.File;4 ImportJava.io.FileReader;5 Importjava.io.IOException;6 ImportJava.io.Reader;7 8 Public classTestreader {9 Public Static voidMain (string[] args)throwsIOException {TenFile file=NewFile ("D:" +file.separator+ "Test.txt"); One /*File*/Reader reader=NewFileReader (file);//you can also receive instantiated objects directly with a variable of type FileReader, without using an upward transformation. A if(File.exists ()) { - Char[] chars=New Char[1024]; - //int Length=reader.read (chars);//read the contents of file into the chars and read it once. the intFoot=0; - intTmp=0; - while((Tmp=reader.read ())!=-1) -Chars[foot++]= (Char) tmp; + reader.close (); - //System.out.println ("" "+new String (chars,0,length) +" "");//print out once read +System.out.println ("" "+NewString (chars,0,foot) + "" "); A } at } -}
View Code
The character input stream of the "Java" IO stream: Java.io.Reader class and Subclass Java.io.FileReader