A quick refresher on creating a Java program that prints out the contents of a file in different ways.
This assignment will give you practice using Eclipse to create a Java program that takes a parameter from the command line.
This project is where we will be doing all our homework assignments for ICS 211. Here’s a screen shot of my Eclipse with my ICS211-workspace project.
This is where we will put all our classes for homework 00.
FileDump should read in the name of a file from the command line.
If the file doesn’t exist then it should throw a FileNotFoundException.
If the file does exist then the program should print out the contents of the file three ways.
As Binary (i.e. the raw binary digits of the file.)
As Hexadecimal, similar to binary, but much more compact.
As Strings UTF-8 encoding. This may show some very strange characters depending on the type of file.
I recommend you create a method for each of the different outputs. Use the FileReader to read the contents of the file a byte at a time. Then you can convert the byte to the correct representation you want to display.
Here is an example of the output for the file Hello.txt. I put spaces between the binary and hexadecimal byes, but didn’t in the string representation. The output of the program should look like:
Binary contents of Hello.txt:
01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100
01100100 00100000 01100110 01110010 01101111 01101101 00100000 01001001 01000011 01010011
00100000 00110010 00110001 00110001 00101110 00001010 01010100 01101000 01101001 01110011
00100000 01101001 01110011 00100000 01110100 01101000 01100101 00100000 01110011 01100101
01100011 01101111 01101110 01100100 00100000 01101100 01101001 01101110 01100101 00101110
Hexadecimal contents Hello.txt:
48 65 6c 6c 6f 20 57 6f 72 6c
64 20 66 72 6f 6d 20 49 43 53
20 32 31 31 2e 0a 54 68 69 73
20 69 73 20 74 68 65 20 73 65
63 6f 6e 64 20 6c 69 6e 65 2e
UTF-8 contents Hello.txt:
Hello World from ICS 211.
This is the second line.
What is the output when you use elipsis.png as the file?
You can configure Eclipse to ask the user for any number of command line arguments. From the Menu choose “Run -> Run Configurations”. You will see a dialog similar to:
Select the (x)= Arguments tab.
Then click in the Program Arguments: field and choose the “Variables..” button. Scroll down till you see the string_prompt choice.
Choose ok.
When you run your program you will see a dialog box like
This is where you can supply the file name.
Criterion | Excellent (100%) | Satisfactory (75%) | Borderline (50%) | Unsatisfactory (25%) | Poor (0) |
---|---|---|---|---|---|
Adherence to standards - 2 points Does it conform to standards in every detail? |
No errors. | Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. | Misses the point of the assignment. |
Breakdown (modular design) - 1 point Does it demonstrate good modular design? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Correctness of code - 4 points Does it work? Does it pass JUnit? |
Passes all tests. | Works for typical input, may fail for minor special cases. | Fails for typical input, for a minor reason. | Fails for typical input, for a major reason. | No. |
Documentation, and style - 2 points Is it clear and maintainable? Does it pass CheckStyle? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Efficiency of code - 1 point Does it use the Java features well? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
The assignment is due on Thursday at 11:55pm. You may turn it in early.
Export your ICS211-workspace project by choosing File -> Export.
Under General choose Archive File.
On the next dialog choose only the src files in your project. Uncheck any other files or directories Name the zip file H00.