实训作业---I/O流

package zuoye;

import java.io.*;
import java.io.File;
public class io {
    public static void main(String[] args) {
        String red="12345abcdef@#%&*软件工程";
        File file=new File("D:\\data.txt");
        try {
            FileWriter fw=new FileWriter(file);
            BufferedWriter bw=new BufferedWriter(fw);
            bw.write(red);
            bw.newLine();
            bw.close();
            fw.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        try {
            FileReader  fr=new FileReader(file);
            BufferedReader bf=new BufferedReader(fr);
            String str1=null;
            while((str1=bf.readLine())!=null) {
                System.out.print(str1);
                 
            }
            bf.close();
            fr.close();
             
             
        }catch(Exception e) {
             
            e.printStackTrace();
        }
                 
    }
 
}

你可能感兴趣的:(实训作业---I/O流)