1 package shurushuchu; 2 import java.io.*; 3 public class IoDemo { 4 5 public static void main(String[] args) { 6 7 try { 8 BufferedReader br=new BufferedReader(new FileReader("d:/test.txt")); 9 String s=br.readLine(); 10 br.close(); 11 System.out.println("s="+s); 12 13 File f1=new File("d:/iodemo.txt"); 14 if(!f1.exists()) 15 { 16 f1.createNewFile(); 17 System.out.println("文本创建成功"); 18 } 19 BufferedWriter bw=new BufferedWriter(new FileWriter("d:/iodemo.txt")); 20 bw.write("追加的文本"); 21 bw.close(); 22 System.out.println("写完"); 23 } 24 catch (Exception e) 25 { 26 // TODO 自动生成的 catch 块 27 e.printStackTrace(); 28 } 29 30 } 31 32 }