1 public class SY63 { 2 public static void main(String[] args) throws Exception { 3 System.out.print("请输入字符串:"); 4 Scanner in = new Scanner(System.in); 5 String st = in.nextLine(); 6 7 FileWriter fw = new FileWriter("d:\test.txt"); 8 fw.write(st); 9 fw.close(); 10 11 FileReader fr = new FileReader("d:\test.txt"); 12 char[] bchar= new char[1024]; 13 int len = 0; 14 while((len = fr.read(bchar)) != -1){ 15 System.out.print(new String(bchar,0,len)); 16 } 17 fr.close(); 18 } 19 }