接收键盘输入的字符串,用FileWirter类将字符串写入文件,用FileReader类读出文件内容显示在屏幕上

 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 }

 

posted @ 2017-12-09 16:41  WETYUIOASHZXCVBNM  阅读(874)  评论(0编辑  收藏  举报