緩衝區的簡單讀取和寫入

public class BufferReader_t {code

public static void main(String[] args)throws Exception {

    File f=new File("d:/test/a.txt");

    // //就是套幾層,這個要本身點源碼進去看下,爲啥要這樣嵌套
	
    BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(f)));
	
    BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new 
	
	File("d:/test/a_1.txt"))));

    String s=null;
	
    while ((s=bufferedReader.readLine())!=null){
	
        bufferedWriter.write(s);
		
        //寫入換行符
		
         bufferedWriter.newLine();
		 
        System.out.println(s);
		
    }
	
    bufferedWriter.close();
	
    bufferedReader.close();
    
}

}源碼

相關文章
相關標籤/搜索