package com.lovecoding.day21.file03;

import org.junit.Test;

import java.io.FileReader;
import java.io.FileWriter;

public class TestReaderWriter {
    //关闭顺序
    @Test
    public void test05() throws Exception {
        //输入
        FileReader fr = new FileReader("aaa.txt");
        //输出
        FileWriter fw = new FileWriter("eee.txt");
        int len = 0;
        char[] chars = new char[4];
        while ( ( len = fr.read(chars) ) != -1 ){
            fw.write(chars,0,len);
        }
        //释放
        fw.close();
        fr.close();


    }

    @Test
    public void test04() throws Exception {
        FileWriter fw = new FileWriter("ddd.txt");

        fw.write("你");
        fw.flush();
        fw.write("好");
        fw.flush();
        fw.write("世");
        fw.flush();
        fw.write("界");

        fw.close();
    }

    @Test
    public void test03() throws Exception {
        FileWriter fw = new FileWriter("ddd.txt");

        fw.write("你");
        fw.write("好");
        fw.write("世");
        fw.write("界");

        fw.close();
    }

    //## 第4题：复制.java文件
    //
    //案例需求：使用文件字符流复制一个.java文件
    //E:\VIP-23\javacode\JavaSE\day21\src\com\lovecoding\day21\file02\TestFileinput02.java
    @Test
    public void test02() throws Exception {
        //输入
        FileReader fr = new FileReader("E:\\VIP-23\\javacode\\JavaSE\\day21\\src\\com\\lovecoding\\day21\\file02\\TestFileinput02.java");
        //输出
        FileWriter fw = new FileWriter("D:\\Hello.java");
        int len = 0;
        while ( ( len = fr.read() ) != -1 ){
            fw.write(len);
        }

        //释放
        fw.close();
        fr.close();


    }


    @Test
    public void test01() throws Exception {
        FileWriter fw = new FileWriter("ccc.txt");

        //写出字符串
        fw.write("太热了");

        fw.close();
    }
}
