java BufferedReader和FileReader有什么區別


FileReader : 字符流
BufferedReader : 也是字符流,但是在BufferedReader可以先把數據放到一個緩存區里,然后在進行處理,而且在BufferedReader 里有一個readLine()方法。
所謂緩沖區,就是能夠一次性讀取一塊緩沖區大小的數據,再從緩沖區中去讀取數據,而不用一點一點地直接從硬盤中抽取數據。
 1  public void loadData(String path) throws IOException
 2     {
 3         BufferedReader br = new BufferedReader(new FileReader(new File(path)));
 4         String line = br.readLine();
 5         while (line != null)
 6         {
 7             String[] segs = line.split("\\s");
 8             String label = segs[0];
 9             List<String> fieldList = new ArrayList<String>();
10             for (int i = 1; i < segs.length; ++i)
11             {
12                 fieldList.add(segs[i]);
13                 Feature feature = new Feature(label, segs[i]);
14                 int index = featureList.indexOf(feature);
15                 if (index == -1)
16                 {
17                     featureList.add(feature);
18                     featureCountList.add(1);
19                 }
20                 else
21                 {
22                     featureCountList.set(index, featureCountList.get(index) + 1);
23                 }
24             }
25             if (fieldList.size() > C) C = fieldList.size();
26             Instance instance = new Instance(label, fieldList);
27             instanceList.add(instance);
28             if (labels.indexOf(label) == -1) labels.add(label);
29             line = br.readLine();
30         }
31     }
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM