Copy the C-drive text file to the D drive.

Source: Internet
Author: User

Copy the C-drive text file to the D drive.
/*
The principle of replication:
In fact, the file data under the C drive is stored in a file on the D drive.

Steps:
1. Create a file in the D drive to store the data in the C drive file.
2. Define read stream and C-Drive file association.
3, through continuous reading and writing to complete the data storage.
4, close the resources.
*/

 Public classCopyText { Public Static voidMain (string[] args)throwsIOException {copy_2 (); }     Public Static voidcopy_2 () {FileWriter FW=NULL; FileReader FR=NULL; Try{FW=NewFileWriter ("Systemdemo_copy.txt"); Fr=NewFileReader ("Systemdemo.java"); Char[] buf =New Char[1024]; intLen = 0;  while((Len=fr.read (BUF))!=-1) {fw.write (buf,0, Len); }        }        Catch(IOException e) {Throw NewRuntimeException ("Read and Write Failed"); }        finally        {            if(fr!=NULL)                Try{fr.close (); }                Catch(IOException e) {}if(fw!=NULL)                Try{fw.close (); }                Catch(IOException e) {}}} //read a character from the C drive and write a character to the D drive.      Public Static voidCopy_1 ()throwsIOException {//Create a destination. FileWriter FW =NewFileWriter ("Runtimedemo_copy.txt"); //associated with an existing file. FileReader FR =NewFileReader ("Runtimedemo.java"); intCH = 0;  while((Ch=fr.read ())!=-1) {fw.write (CH);        } fw.close ();    Fr.close (); }    }

Copy the C-drive text file to the D drive.

Related Article

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.