Design 1Program(Copy. Java), which allows you to copy files.
Requirements:Simulate the Copy command of Dos. Input two path names to copy the file. If you enter the following command Java copy F: \ 1.txt F :\\ 2.txt, the contents of F :\\ 1.txt will be copied to f :\\ 2.txt.
Tip:You can use file, fileinputstream, and fileoutputstream.
Package Com. CMM. io4; Import Java. Io .* ; Public Class Copy { /** * @ Param Arg * @ Peter Cao */ Public Static Void Main (string [] ARGs ){ // Todo auto-generated method stub String filepath1 = "" ; String filepath2 = "" ; File file1 = Null ; File file2 = Null ; Byte [] Bt = New Byte [1024 ]; If (ARGs. Length = 2 ) {Filepath1 = ARGs [0 ]; Filepath2 = ARGs [1 ]; File1 = New File (filepath1); file2 = New File (filepath2 ); If (File1.exists ()&& File1.isfile ()){ Try { // Fileinputstream -- bufferedinputstream Fileinputstream fins = New Fileinputstream (file1); bufferedinputstream bins = New Bufferedinputstream (FINS ); // Bufferedinputstream bins = new bufferedinputstream (New fileinputstream (file1 )); // Fileoutputstream -- bufferedoutputstream Fileoutputstream Fouts = New Fileoutputstream (file2); bufferedoutputstream bouts = New Bufferedoutputstream (Fouts ); If (! File2.exists () {file2.createnewfile (); // If the file does not exist, create the file. } While (Bins. Read (BT)> 0) // Or bins. Read (BT )! =-1 {Bouts. Write (BT); bouts. Flush (); BT = New Byte [1024]; // Refresh byte [] } Bouts. Close (); Fouts. Close (); bins. Close (); fins. Close ();} Catch (Exception e) {e. printstacktrace ();}}}}}