IO

时间:2019-06-12
本文章向大家介绍IO,主要包括IO使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
package work;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class OutputData {
    public OutputData(String str)
    {
        File f = new File("data.txt");
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(f));
            bw.write(str);
            bw.close();
        } catch (IOException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        String str = "12345abcdef@#%&*软件工程";
        new OutputData(str);

    }

}
package work;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

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();

    }

}

原文地址:https://www.cnblogs.com/jdjdj/p/11010565.html