Write a program that asks the user for the name of an input text file. The text file (which could be created with NotePad) will contain integers in character format, one per line, such as follows.
The program also asks for the name of an output file. The program then reads the input file line by line until end of file. Each input integer is translated into int data (use Integer.parseInt()) and written to the output file using DataOutputStream.writeInt().
Look at the input file and output file with the DOS command DIR and, if possible, with a hex dump program.
Input file -->ints.txt
Output file -->ints.bin
06/16/00 04:33p 1,881 IntCopy.class
06/16/00 04:33p 1,920 IntCopy.java
06/16/00 04:35p 24 ints.bin
06/16/00 04:35p 30 ints.txt
Write the input loop so it catches NumberFormatExceptions and echos the offending line. Here is another input file:
Rats, this won't work
And the corresponding run of the program:
Input file -->oops.txt
Output file -->opps.bin
Poor input data:Rats, this won't work