/****************************************************************************** * This program reads bytes from a binary file and copies them to another file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.pureprogrammer.Utils; public class FileIO9 { static void copyBinaryFile(String fromFilespec, String toFilespec) throws IOException { BufferedInputStream ifh = new BufferedInputStream(new FileInputStream(fromFilespec)); BufferedOutputStream ofh = new BufferedOutputStream(new FileOutputStream(toFilespec)); int c; while ((c = Utils.getbyte(ifh)) != -1) { ofh.write(c); } try {ifh.close();} catch (IOException ex) {}; try {ofh.close();} catch (IOException ex) {}; } public static void main(String[] args) { if (args.length != 2) { System.out.println(Utils.join("", "Syntax: ", "FileIO9", " {fromFilespec} {toFilespec}")); System.exit(1); } String fromFilespec = args[0]; String toFilespec = args[1]; try { copyBinaryFile(fromFilespec, toFilespec); } catch (IOException ex) { System.out.println(Utils.join("", "Error: ", Utils.exceptionMessage(ex))); } } }