I/O流

java实训作业----IO流

 
复制代码
import java.io.*;

public class FileTest {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        File file = new File("data.txt");
        String s = "12345abcdef@#%&*软件工程";
        try {
            FileWriter te = new FileWriter (file);
            BufferedWriter out = new BufferedWriter (te);
            out.write(s);
            out.close();
            te.close();

        } catch (Exception e) {
            e.printStackTrace();
        } 
        try {
            FileReader fr = new FileReader(file);
            BufferedReader in = new BufferedReader(fr);
            String len = in.readLine();
            System.out.println("文件中的信息是:"+ len);
            in.close();
            fr.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

}
复制代码

本次实训的心得:

你可能感兴趣的:(I/O流)