Usage of FileReader:
1 Import Staticorg.junit.assert.*;2 3 ImportJava.io.File;4 Importjava.io.FileNotFoundException;5 ImportJava.io.FileReader;6 ImportJava.io.FileWriter;7 Importjava.io.IOException;8 9 Importorg.junit.Test;Ten One ImportCom.sun.org.apache.bcel.internal.generic.NEW; A - - the - Public classMyTest { - //writes data to a specified file by a character stream - @Test + Public voidTestwrite ()throwsIOException { -String Path = "F:" +file.separator+ "Demo.txt"; +FileReader FileReader =NULL; A Try { atFileReader =NewFileReader (path); - Char[] buf =New Char[10]; - intTemp =0; - //FileReader to read 10 characters, and put the read character into the BUF array, the actual number of characters to supervise the existence of a temp - while(temp = Filereader.read (buf))!=-1){ -System.out.println (NewString (buf,0, temp)); in } - to}Catch(FileNotFoundException e) { + //TODO auto-generated Catch block - e.printstacktrace (); the } * $ Panax Notoginseng } - the}
char[] buf = new char[100];
。。。 Io Stream Learning II ...