binary file copy

PHOTO EMBED

Thu Jan 18 2024 18:15:22 GMT+0000 (Coordinated Universal Time)

Saved by @login

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Copy {
    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("Usage: java Copy <sourceFilePath> <destinationFilePath>");
            return;
        }

        try (
            FileInputStream fis = new FileInputStream(args[0]);
            FileOutputStream fos = new FileOutputStream(args[1])
        ) {
            byte[] contents = new byte[fis.available()];
            fis.read(contents);
            fos.write(contents);
            System.out.println("Contents Copied");
        } catch (FileNotFoundException e) {
            System.out.println("File not found: " + e.getMessage());
        } catch (IOException e) {
            System.out.println("Error reading or writing the file: " + e.getMessage());
        }
    }
}
content_copyCOPY