import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException{ //字符轉(zhuǎn)換流,一次讀寫一個字符 /*FileReader fr =new FileReader(new File("11.txt")); FileWriter fw = new FileWriter(new File("22.txt")); int len =0; while((len = fr.read())!=-1){ fw.write(len); } if(fr!=null){ fr.close(); } if(fw!=null){ fw.close(); }*/ //字符轉(zhuǎn)換流,一次讀寫一組字符。 /*FileReader fr =new FileReader(new File("11.txt")); FileWriter fw = new FileWriter(new File("22.txt")); char[] chs = new char[1024]; int len = 0; while ((len = fr.read(chs)) != -1) { fw.write(chs, 0, len); } if(fr!=null){ fr.close(); } if(fw!=null){ fw.close(); }*/ //字符緩沖流,一次讀寫一個字符 /*BufferedReader br =new BufferedReader(new FileReader("11.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("22.txt")); int str=0; while((str= br.read()) !=-1){ bw.write(str); } if(bw!=null){ bw.close(); } if(br!=null){ br.close(); }*/ //字符緩沖流,一次讀寫一組字符 /*BufferedReader br =new BufferedReader(new FileReader("11.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("22.txt")); char[] chs = new char[1024]; int len = 0; while ((len = br.read(chs)) != -1) { bw.write(chs, 0, len); } if(bw!=null){ bw.close(); } if(br!=null){ br.close(); }*/ //字符緩沖流,一次讀寫一個字符串。
BufferedReader br =new BufferedReader(new FileReader("11.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("22.txt")); String str = null; while((str= br.readLine()) !=null){ bw.write(str); bw.newLine(); bw.flush(); } if(bw!=null){ bw.close(); } if(br!=null){ br.close(); } } } |
|