标签:android blog http io ar os java sp for
字符流读写文件时,以字符为基础
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]); }
标签:android blog http io ar os java sp for
原文地址:http://www.cnblogs.com/chavez-wang/p/4082550.html