标签:
fileReader的用法:
1 import static org.junit.Assert.*; 2 3 import java.io.File; 4 import java.io.FileNotFoundException; 5 import java.io.FileReader; 6 import java.io.FileWriter; 7 import java.io.IOException; 8 9 import org.junit.Test; 10 11 import com.sun.org.apache.bcel.internal.generic.NEW; 12 13 14 15 16 public class MyTest { 17 //通过字符流写入数据到指定的文件中 18 @Test 19 public void testWrite() throws IOException { 20 String path = "F:"+File.separator+"demo.txt"; 21 FileReader fileReader = null; 22 try { 23 fileReader = new FileReader(path); 24 char[] buf = new char[10]; 25 int temp =0; 26 // fileReader去读取10个字符,并且将读取到的字符放到buf数组里面,实际督导多少个字符的个数存在temp中 27 while((temp = fileReader.read(buf))!=-1){ 28 System.out.println(new String(buf,0,temp)); 29 } 30 31 } catch (FileNotFoundException e) { 32 // TODO Auto-generated catch block 33 e.printStackTrace(); 34 } 35 36 37 } 38 39 }
char[] buf = new char[100];
标签:
原文地址:http://www.cnblogs.com/yingmeng/p/5860204.html