Java基础-简单的字符流-FileReader,FileWriter

简介:如题

package com.cc.test;

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

public class TestChar {

            
    public static void main(String[] args) {

        FileReader fReader = null;
        FileWriter fWriter = null;
        try{
            fReader = new FileReader("E:/Android/AndroidStudioProjects/text.txt");
            fWriter = new FileWriter("E:/Android/AndroidStudioProjects/store.txt");
            
            char [] cbuf = new char[100];
            fReader.read(cbuf, 0, cbuf.length);
            for(int i = 0;i < cbuf.length;i++){
                System.out.println(cbuf[i]);
            }
            fWriter.write(cbuf, 0, cbuf.length);
            
        }
        catch(Exception e){
            System.out.println(e);
            System.out.println("1---e");
        }
        finally{
            try{
                fReader.close();
                fWriter.close();
            }
            catch(Exception e){
                System.out.println(e);
                System.out.println("2---- e");
            }

        }
    }
}

console:正常

image

 

读取正常

写入正常

posted @ 2015-07-10 23:23  cuiz_book  阅读(251)  评论(0编辑  收藏  举报