InoutStream和outPutStream在读取文件的时候操作的都是字节,同字节流一样字符流也有两个抽象的顶级父类。Reader和Writer。其中主要有FileReader/Writer和BufferderReader/Writer常用子类
    一、Reader:字符输入流FileReader

    1. package com.package18;
    2. import java.io.FileReader;
    3. import java.io.IOException;
    4. public class ReaderDemo {
    5. public static void main(String[] args)throws IOException {
    6. FileReader reader= new FileReader("./out.txt");
    7. int le=0;
    8. while ((le=reader.read())!=-1){
    9. System.out.print((char) le);
    10. }
    11. }
    12. }

    二、Writer:字符输出流FileWriter

    1. package com.package18;
    2. import java.io.FileWriter;
    3. import java.io.IOException;
    4. public class WriterDemo {
    5. public static void main(String[] args) throws IOException {
    6. FileWriter fileWriter = new FileWriter("./text/writer.text");
    7. String str="轻轻的我走了,正如我轻轻的来;\n" +
    8. "我轻轻的招手,作别西天的云彩。\n" +
    9. "那河畔的金柳,是夕阳中的新娘;\n" +
    10. "波光里的艳影,在我的心头荡漾。\n" +
    11. "软泥上的青荇,油油的在水底招摇;\n" +
    12. "在康河的柔波里,我甘心做一条水草!\n" +
    13. "那榆荫下的一潭,不是清泉,是天上虹;\n" +
    14. "揉碎在浮藻间,沉淀着彩虹似的梦。\n" +
    15. "寻梦?\n" +
    16. "撑一支长篙,向青草更青处漫溯;\n" +
    17. "满载一船星辉,在星辉斑斓里放歌。\n" +
    18. "但我不能放歌,悄悄是别离的笙箫;\n" +
    19. "夏虫也为我沉默,沉默是今晚的康桥!\n" +
    20. "悄悄的我走了,正如我悄悄的来;\n" +
    21. "我挥一挥衣袖,不带走一片云彩。";
    22. fileWriter.write(str);
    23. fileWriter.close();
    24. }
    25. }

    三、字符缓冲流:
    ①:使用字符缓冲区来复制文件:

    1. public class CopyDemo2 {
    2. public static void main(String[] args)throws IOException {
    3. FileReader reader = new FileReader("./text/writer.text");
    4. FileWriter fileWriter = new FileWriter("./text/writer2.text");
    5. int temp=0;
    6. char []buff=new char[1024];
    7. while ((temp=reader.read(buff))!=-1){
    8. fileWriter.write(buff,0,temp);
    9. }
    10. reader.close();
    11. fileWriter.close();
    12. }
    13. }
    1. <br />②:BufferdReader和BufferdWiter两个类也同样在其内部定义了8192大小的字节数组。
    1. public class CopyDemo3 {
    2. public static void main(String[] args)throws IOException {
    3. BufferedReader bufferedReader = new BufferedReader(new FileReader("./text/writer.text"));
    4. BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("./text/writer3.text"));
    5. String str=null;
    6. while ((str=bufferedReader.readLine())!=null){
    7. bufferedWriter.write(str);
    8. bufferedWriter.newLine();//换行符,根据不同的操作系统生成不同的换行符
    9. }
    10. bufferedReader.close();
    11. bufferedWriter.close();
    12. }
    13. }