码迷,mamicode.com
首页 > 其他好文 > 详细

。。。IO流学习之二。。。

时间:2016-09-10 22:01:13      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

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];

技术分享

 


。。。IO流学习之二。。。

标签:

原文地址:http://www.cnblogs.com/yingmeng/p/5860204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!