实训作业--------IO流

1、

package bbb;
import java.io.*;

import java.io.IOException;

public class FileDemo
{
  public static void main(String[] args)
  {
  String str="12345abcdef@#%&*软件工程";
      FileWriter writer;
      try {
          writer = new FileWriter("data。tex");
          writer.write(str);
          writer.flush();
          writer.close();
   system.out.printfln("写入成功!")
      } catch (IOException e) {
          e.printStackTrace();
      }
 
2、
package bbb;
import java.io.*;
public class InputData {  
  public InputData()    {  
      File f = new File("data.txt");
            try {               
     BufferedReader br = new BufferedReader(new FileReader(f)); 
               String str = br.readLine(); 
               System.out.println(str); 
               br.close(); 
           } catch (FileNotFoundException e) { 
               // TODO 自动生成的 catch 块 
               e.printStackTrace();            } catch (IOException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();            }  
                      }   
 public static void main(String[] args) { 
       new InputData();    }
}
 }
 }
posted @ 2019-06-12 16:37  延迟满足  阅读(142)  评论(1编辑  收藏  举报