字符流读写文件时,以字符为基础
I/O当中字符流的核心类
Reader类和Writer类是所有字符流类的父类,同样也是抽象类。FileReader和FileWriter分别是它们的子类。
核心类的核心方法:
Reader:
int read(char [] c, int off, int len);
Writer:
void write(char [] c, int off, int len);
import java.io.*;public class Test{public static void main(String args[]){FileReader fr = null;FileWriter fw = null;try{fr = new FileReader("F:/Android/Java4Android/33/src/a.txt");fw = new FileWriter("F:/Android/Java4Android/33/src/b.txt");char [] c = new char [100];int cLen = fr.read(c,0,c.length);fw.write(c,0,cLen);}catch(Exception e){System.out.PRintln(e);}finally{try{fr.close();fw.close();}catch(Exception e){System.out.println(e);}}}}
for(int i = 0;i <c.length;i++){System.out.println(c[i]);}
新闻热点
疑难解答