fileReader的用法:
import static org.junit.Assert.*; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import org.junit.Test; import com.sun.org.apache.bcel.internal.generic.NEW; public class MyTest { //通过字符流写入数据到指定的文件中 @Test public void testWrite() throws IOException { String path = "F:"+File.separator+"demo.txt"; FileReader fileReader = null; try { fileReader = new FileReader(path); char[] buf = new char[10]; int temp =0; // fileReader去读取10个字符,并且将读取到的字符放到buf数组里面,实际督导多少个字符的个数存在temp中 while((temp = fileReader.read(buf))!=-1){ System.out.println(new String(buf,0,temp)); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
char[] buf = new char[100];