檔案讀寫——java
import java.io.FileReader; import java.io.BufferedReader; import java.io.FileWriter; import java.io.BufferedWriter;
class Test{ public static void main(String[] args){ FileReader fr=null; BufferedReader br=null; FileWriter fw=null; BufferedWriter bw=null; try{ fr=new FileReader("C:/Users/Administrator/Desktop/in.txt"); fw=new FileWriter("C:/Users/Administrator/Desktop/out.txt"); br=new BufferedReader(fr); bw=new BufferedWriter(fw);
String s; while(true){ s=br.readLine(); if(s==null){ break; } System.out.println(s); bw.write(s); bw.newLine(); bw.flush(); }
} catch(Exception e){ System.out.println(e); } finally{ try{ fr.close(); fw.close(); br.close(); bw.close(); } catch(Exception e){ System.out.println(e); } } } }