Advertisement
romancha

FileThird

Mar 14th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.util.Arrays;
  6.  
  7. public class MyFileCopy {
  8.     public static void main(String[] args) {
  9.         if (args.length >= 2) {
  10.             try (FileInputStream input = new FileInputStream(args[0]);
  11.                  FileOutputStream output = new FileOutputStream(args[1])) {
  12.  
  13.                 byte[] buf = new byte[1024];
  14.                 int bytesRead;
  15.                 while ((bytesRead = input.read(buf)) > 0) {
  16.                     output.write(buf, 0, bytesRead);
  17.                 }
  18.                 System.out.println("File copied!");
  19.             } catch (IOException e) {
  20.                 System.out.println("Incorrect file args: " + Arrays.toString(args));
  21.             }
  22.         } else {
  23.             System.out.println("Incorrect args!");
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement