復(fù)制文件一共有五種方法:
1、一個(gè)字符的傳輸
2、一個(gè)字符數(shù)組的傳輸
3蓖谢、緩沖流一個(gè)字符的傳輸
4、緩沖流一個(gè)數(shù)組的傳輸
5譬涡、特殊方法newline()的傳輸
接下來(lái)一一對(duì)其分析
首先是幾個(gè)對(duì)象的的構(gòu)建
? ? 1闪幽、FileReader fr = new FileReader("src");? ?FileWriter fw = new FileWriter("src");
? ? 2、BufferReader br = new BufferReader("new FileReader("src")");
? ? ? ? BufferWriter bw = new BufferWriter("new FileWriter("src")");
最后記得使用close()涡匀;
1盯腌、一個(gè)字符:
? ? ? ? char ch ;
? ? ? ? while((ch = fr.read()) != -1){
? ? ? ? ? ? fr.fw("src");
? ? ? ? }
2、字符數(shù)組
? ? char ch = char[1024];
? ? while((ch = fr.read(src) != -1)){
? ? ? ? ? ? fw.write(ch,0,len);
????????}
3陨瘩、String line ;
? ? while((line = fr.readLine()) != null){
? ? ? ? ? ? bw.write(line);
? ? ? ? ? ? bw.nextLine();
? ? ? ? ? ? bw.flush();
????????}