package com.sf.day20;

import org.junit.Test;

import java.io.*;

public class Test01 {
    //fileWriter
    @Test
    public void t1() throws IOException {
        FileWriter fileWriter = new FileWriter(new File("D:\\c.txt"));
        fileWriter.write(97);
        fileWriter.write('b');
        fileWriter.write('c');
        fileWriter.write(30000);
        fileWriter.close();
    }

    @Test
    public void t2() throws IOException {
        FileWriter fileWriter = new FileWriter(new File("abc.txt"),true);
        String str = "xiaoniankuailehappynewyear";
        char[] chars = str.toCharArray();
        //写出
        fileWriter.write(chars);
        fileWriter.close();
    }

    @Test
    public void t3() throws IOException {
        FileReader fileReader = new FileReader(new File("D:\\a.txt"));
        FileWriter fileWriter = new FileWriter(new File("D:\\d.txt"),true);
        char[] chars = new char[5];
        int data;
        while ((data = fileReader.read(chars)) != -1){
            fileWriter.write(chars);
        }
        fileReader.close();
        fileWriter.close();
    }

    @Test
    public void t4() throws IOException {
        FileWriter fileWriter = new FileWriter(new File("fw.txt"));
        fileWriter.write('爱');
        fileWriter.write('扣');
        fileWriter.write('钉');
        fileWriter.write(45000);
        fileWriter.flush();
        fileWriter.close();
    }


}
