/****************************************************************************** * This program simply writes the bytes 0 - 256 to a binary file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.IOException; import org.pureprogrammer.Utils; public class FileIO6 { static void writeBinaryFile(String filespec) throws IOException { BufferedOutputStream ofh = new BufferedOutputStream(new FileOutputStream(filespec)); for (int b = 0; b <= 255; ++b) { ofh.write(b); } try {ofh.close();} catch (IOException ex) {}; } public static void main(String[] args) { if (args.length != 1) { System.out.println(Utils.join("", "Syntax: ", "FileIO6", " {filename}")); System.exit(1); } String filespec = args[0]; try { writeBinaryFile(filespec); } catch (IOException ex) { System.out.println(Utils.join("", "Error: ", Utils.exceptionMessage(ex))); } } }