Java Streams   «Prev  Next»

Read File Names in Java - Exercise

Write a program whose main() method reads a series of filenames from the command line. Each filename should be passed to a method that opens the file. The data should be read from the file and then printed on System.out.
Exactly how the data is printed on System.out will be selected by a command line switch.
If the user selects ASCII format (-a), then the data will be assumed to be ASCII (more properly ISO Latin-1) text and printed as chars.
If the user selects decimal dump (-d), then each byte should be printed as unsigned decimal numbers between 0 and 255, 15 to a line.
For example,

000 234 127 034 234 234 000 000 000 002 004 070 000 234 127 

For hex dump format (-h), each byte should be printed as two hexadecimal digits. For example,
CA FE BA BE 07 89 9A 65 45 65 43 6F F6 7F 8F EE E5 67 63 26 98 9E 9C
Make ASCII format the default.
Paste the source code below and click the Submit button when you are ready to submit this exercise.