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.