zoukankan      html  css  js  c++  java
  • java 缓冲流

    english.txt

    The arrow missed the target.
    They rejected the union demand.
    Where does this road go to?
    Where does this road go to?

    Example10_7.java

    import java.io.*;
    import java.util.*;
    public class Example10_7 {
       public static void main(String args[]) {
          File fRead = new File("english.txt");
          File fWrite = new File("englishCount.txt");
          try{  Writer out = new FileWriter(fWrite);
                BufferedWriter bufferWrite = new BufferedWriter(out);
                Reader in = new FileReader(fRead);
                BufferedReader bufferRead =new BufferedReader(in);
                String str = null;
                while((str=bufferRead.readLine())!=null) {
                   StringTokenizer fenxi = new StringTokenizer(str);
                   int count=fenxi.countTokens();
                   str = str+" 句子中单词个数:"+count;
                   bufferWrite.write(str);
                   bufferWrite.newLine();
                } 
                bufferWrite.close(); 
                out.close();
                in = new FileReader(fWrite);
                bufferRead =new BufferedReader(in);
                String s=null;
                System.out.println(fWrite.getName()+"内容:");
                while((s=bufferRead.readLine())!=null) {
                  System.out.println(s);
               }  
               bufferRead.close();
               in.close();
          }
          catch(IOException e) {
              System.out.println(e.toString());
          }
       }
    }
  • 相关阅读:
    JSP前三章测试改错
    实现文件上传
    Url和Uri的区别
    四套读写文件方案
    C++第一课
    数据聚合架构模式
    高并发怎么解决?
    为什么做不了软件架构师
    完整版go-mysql-elasticsearch安装步骤
    安装GO
  • 原文地址:https://www.cnblogs.com/yihujiu/p/5990812.html
Copyright © 2011-2022 走看看