Advertisement
joseleonweb

Untitled

Feb 28th, 2021
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class CopyFile2 {
  4.     public static void main(String[] args) throws IOException
  5.     {
  6.         int i;
  7.        
  8.         // First, confirm that both files has been specified.
  9.         if(args.length != 2) {
  10.             System.out.println("Usage: CopyFile from to");
  11.             return;
  12.         }
  13.        
  14.         // Open and manage two files via the try statement.
  15.         try(FileInputStream fin = new FileInputStream(args[0]);
  16.             FileOutputStream fout = new FileOutputStream(args[1]))
  17.         {
  18.            
  19.             do {
  20.                 i = fin.read();            // Read bytes from one file
  21.                 if(i != -1) fout.write(i); // and write them to another
  22.             } while(i != -1);
  23.        
  24.         } catch(IOException exc) {
  25.             System.out.println("I/O Error: " + exc);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement