天天看點

字元流的讀寫操作

//  純文字的讀寫操作 ,優先考慮字元流

public  void   readerAndWriter(){

//  建立字元流的讀寫對象

try {

FileReader   fr=new FileReader("h:/a.txt");

FileWriter    fw=new FileWriter("h:/c.txt");

char []  cs=new char[1024];

long  start =System.currentTimeMillis();

//  讀寫操作

int len= fr.read(cs);

while(len!=-1){

fw.write(cs,0,len);

len=fr.read(cs);

}

long  end=System.currentTimeMillis();

System.out.println("字元流讀寫:"+(end-start));

fr.close();

fw.flush();

fw.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

上一篇: I/O流--File類