import java.util.*; import java.io.*; public class NumberWriter { public static void main(String[] args) throws IOException { Scanner console = new Scanner(System.in); System.out.print("What file would you like to write to? "); String file = console.nextLine().trim(); PrintStream output = new PrintStream(new File(file)); /* BitInputStream and BitOutputStream assume that the * first byte in the file is an indication of how many * garbage bits are at the end of the file. In the Huffman * assignment, all files that are read by BitInputStream will * have been written by BitOutputStream; so, you don't have to * worry about this. */ output.write(0); boolean end = false; while (!end) { System.out.print("What number would you like to write? "); int num = Integer.parseInt(console.nextLine()); /* Output the number to the file */ output.write(num); System.out.print("Would you like to enter another number (y/n)? "); end = console.nextLine().trim().toLowerCase().startsWith("y"); } } }