Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class CopyFile2 {
- public static void main(String[] args) throws IOException
- {
- int i;
- // First, confirm that both files has been specified.
- if(args.length != 2) {
- System.out.println("Usage: CopyFile from to");
- return;
- }
- // Open and manage two files via the try statement.
- try(FileInputStream fin = new FileInputStream(args[0]);
- FileOutputStream fout = new FileOutputStream(args[1]))
- {
- do {
- i = fin.read(); // Read bytes from one file
- if(i != -1) fout.write(i); // and write them to another
- } while(i != -1);
- } catch(IOException exc) {
- System.out.println("I/O Error: " + exc);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement