IO: Copy a file from C disk to D disk

Source: Internet
Author: 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
/* Exercise: Copy a file from C to disk D
Ideas
* 1.C Disk File is a source of data
* Copy to D disk, stating that D disk is the purpose of data storage, there should be a file in this purpose
* 2. Read the file in C and write the data to the destination
* 3. Since the operation of the text file, as long as the use of character streams can be.
*/
1. Create a character read stream object and source correlation
FileReader fr= New FileReader ("F:\\demo2.txt");

2. Create a character output stream object that explicitly wants to store the data
FileWriter fw= New FileWriter ("Demo5.txt");

3. Read-write operation, reading one, write one.
int ch=0;
while ((Ch=fr.read ())!=-1) {
Fw.write (CH);
}

4. Closing Resources
Fw.close ();
Fr.close ();


}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.