IO:將C盤的一個檔案複製到D盤__字元流

來源:互聯網
上載者:User
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class deom5 {


public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
/*練習:將C盤的一個檔案複製到D盤
* 思路:
* 1.C盤的檔案是一個資料的源
* 複製到的D盤,說明D盤是資料的儲存的目的,該目的中應該有一個檔案
* 2.先讀取C盤的檔案,將讀取奧的資料寫入到目的地中
* 3.既然是操作文字檔,只要使用字元流即可。
*/
//1.建立字元讀取流對象和源相關聯
FileReader fr= new FileReader("F:\\demo2.txt");

//2.建立字元輸出資料流對象,明確要儲存資料的目的
FileWriter fw= new FileWriter("demo5.txt");

//3.進行讀寫操作,讀取一個,就寫入一個。
int ch=0;
while((ch=fr.read())!=-1){
fw.write(ch);
}

//4.關閉資源
fw.close();
fr.close();


}


}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.