zoukankan      html  css  js  c++  java
  • 流的append

    StringBuffer的引用
    1
    public static void main(String[] args) throws IOException { 2 3 File file = new File("a.txt"); 4 5 Reader reader = new FileReader(file); 6 7 System.out.println((char) reader.read()); 8 9 char[] cbuf = new char[5]; 10 reader.read(cbuf); 11 System.out.println(new String(cbuf)); 12 13 char[] chars = new char[1024]; 14 int len = -1; 15 StringBuffer stringBuffer = new StringBuffer(); 16 while ((len = reader.read(chars)) != -1) { 17 stringBuffer.append(chars, 0, len); 18 19 } 20 21 System.out.println(stringBuffer.toString()); 22 23 reader.close(); 24 25 }

    调用方法的参数追加

     1 public class CopeText {
     2     public static void main(String[] args) throws IOException {
     3         cope();
     4     }
     5     
     6     private static void cope() throws IOException {
     7         FileReader fr=new FileReader("a.txt");
     8         FileWriter fw=new FileWriter("b.txt",true);
     9         char[] buff=new char[1024];
    10         int len=-1;
    11         if((len=fr.read(buff))!=-1){
    12             
    13             fw.write(buff,0,len);
    14         }
    15         fw.close();
    16         fr.close();
    17     }
    18 }
  • 相关阅读:
    HTTP 的学习
    标量方程求解
    限制器
    差分格式
    Archlinux的基本配置
    布拉休斯方程数值求解
    GNU大型项目构建和覆盖率生成(第一篇)
    plot3d网格读取写入与可视化
    abaqus中的约束
    向量范数和矩阵范数
  • 原文地址:https://www.cnblogs.com/java-log/p/7445538.html
Copyright © 2011-2022 走看看