No, it only reminds the user of the correct order. The user is expected to start the program without arguments to get a reminder.
The class File
could be
used to check if a file already
exists (and then not used as the destination).
The program could be improved by using that class.
But for now, here is the complete program:
import java.io.*; class CopyBytes { public static void main ( String[] args ) { DataInputStream instr; DataOutputStream outstr; if ( args.length != 3 || !args[1].toUpperCase().equals("TO") ) { System.out.println("java CopyBytes source to destination"); return; } try { instr = new DataInputStream( new BufferedInputStream( new FileInputStream( args[0] ))); outstr = new DataOutputStream( new BufferedOutputStream( new FileOutputStream( args[2] ))); try { int data; while ( true ) { data = instr.readUnsignedByte() ; outstr.writeByte( data ) ; } } catch ( EOFException eof ) { outstr.close(); instr.close(); return; } } catch ( FileNotFoundException nfx ) { System.out.println("Problem opening files" ); } catch ( IOException iox ) { System.out.println("IO Problems" ); } } }
A computer's operating system comes with a file copy command, so there is no practical use for this program. But it is a foundation for many programs that are of practical use. Various data transformations can be done by slipping in some statements between the reading and the writing of the byte.
(Thought question: ) What modification will change this program so that it counts the number of bytes in a file?