java字符流写入数据


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

//字符流写数据的五种方式
public class OutputStreamWrite1 {
    public static void main(String[] args) throws IOException {
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream("E:\\Workpace\\abc.txt"));
        //outputStreamWriter = new OutputStreamWriter(new FileOutputStream("E:\\Workpace\\abc.txt"), StandardCharsets.UTF_8);
        //1.单个写入
        outputStreamWriter.write("a");
        //2.数组写入
        char c[] = {'a','v','c','e'};
        outputStreamWriter.write(c);
        //3.写入数组一部分
        outputStreamWriter.write(c,1,3);
        //4.字符串写入
        outputStreamWriter.write("中国");
        //5.字符串的一部分
        outputStreamWriter.write("中国",0,1);
        outputStreamWriter.flush();
        outputStreamWriter.close();
    }
}


posted @ 2021-05-01 10:46  code-G  阅读(252)  评论(0编辑  收藏  举报