1 package shurushuchuliu; 2 import java.io.*; 3 public class Test5 { 4 5 public static void main(String[] args) { 6 try { 7 // 缓存的流 8 //匿名对象 9 10 BufferedWriter bw=new BufferedWriter(new FileWriter("d:/test.txt")); 11 bw.write("测试的缓存语句"); 12 bw.close(); 13 System.out.println("写入完成"); 14 //读 15 BufferedReader br=new BufferedReader(new FileReader("d:/test.txt")); 16 17 String str=br.readLine(); 18 br.close(); 19 System.out.println("str="+str 20 ); 21 } 22 catch (Exception e) 23 { 24 // TODO 自动生成的 catch 块 25 e.printStackTrace(); 26 } 27 28 } 29 30 }