上机作业——i/o

 1 import java.io.*;
 2 
 3 public class delet {
 4     public static void main(String[]args){
 5         String str = "212313撒旦 大是";
 6         File file = new File("data.txt");
 7         if(file.exists()){
 8             try {
 9                 file.createNewFile();
10             } catch (IOException e) {
11                 e.printStackTrace();
12             }
13 
14         }else{
15             System.out.println("fill");
16         }
17         try{
18             FileWriter writer = new FileWriter(file,true);
19             writer.write(str);
20             writer.close();
21         } catch (Exception e) {
22             e.printStackTrace();
23         }
24         try{
25             FileReader reader = null;
26             try {
27                 reader = new FileReader(file);
28                 char a[] = new char[1024];
29                 int length = reader.read(a);
30                 System.out.println(new String(a,0,length));
31                 reader.close();
32             } catch (IOException e) {
33                 e.printStackTrace();
34             }
35             
36             
37         }
38     }
39 }

 

posted @ 2019-06-18 10:01  一个人的姐姐  阅读(195)  评论(0编辑  收藏  举报