流的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 }
原文地址:https://www.cnblogs.com/java-log/p/7445538.html