Java基礎-簡單的字符流-FileReader,FileWriter

簡介:如題java

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:正常spa

image

 

讀取正常code

寫入正常blog

相關文章
相關標籤/搜索