joseleonweb

Untitled

Feb 27th, 2021
747
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2.  
  3. public class CopyFile {
  4.     public static void main(String[] args) throws IOException
  5.     {
  6.         int i;
  7.         FileInputStream fin = null;
  8.         FileOutputStream fout = null;
  9.        
  10.         // First, make sure that both files has been specified.
  11.         if(args.length != 2) {
  12.             System.out.println("Usage: Copy File from to");
  13.             return;
  14.         }
  15.        
  16.         // Copy a File
  17.         try {
  18.             // Attempt to open the files
  19.             fin = new FileInputStream(args[0]);
  20.             fout = new FileOutputStream(args[1]);
  21.            
  22.             do {
  23.                 i = fin.read();            // Read bytes from one file
  24.                 if(i != -1) fout.write(i); // and write them to another
  25.             } while(i != -1);
  26.        
  27.         } catch(IOException exc) {
  28.             System.out.println("I/O Error: " + exc);
  29.         } finally {
  30.             try {
  31.                 if(fin != null) fin.close();
  32.             } catch(IOException exc) {
  33.                 System.out.println("Error Closing Input File");
  34.             }
  35.             try {
  36.                 if(fout != null) fin.close();
  37.             } catch(IOException exc) {
  38.                 System.out.println("Error Closing Output File");
  39.             }
  40.         }
  41.     }
  42. }
  43.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×