Get the Lab 12 program files from the "read only" folder and put them in your Lab 12 directory.
This section is not required, but I suggest you try it when you have finished the other parts
Change into subdirectory ListFiles and edit the ListFile class. Complete the program so that it behaves like the UNIX ls command. You will run your program by enteringjava ListFile name of file or directoryIf the name entered is a file name, it should simply be echoed at the console. If it is the name of a directory, all the file names and subdirectory names in that directory should be printed at the console. If there is no file or directory by that name, print an error message. For example, in this subdirectory, there are subdirectories A and B and the file ListFile.java. I should get these results:
$ java ListFile A b c $ java ListFile ListFile.java ListFile.java $ java ListFile D D: No such file or directory
Complete the code in the main() method of ListFile.java.
1 When you are ready, call us over to see your working program and code.
This section is not required, but I suggest you try it when you have finished the other parts
Now modify ListFile.java to use a JFileChooser object instead of getting the file name from the command line. The dialog window should open on the current directory, that is, the one in which ListFile.java is located. Check to see if the user has opened a file or cancelled. If the user has selected a file, print the file name at the console. If the user has cancelled, print "dialog cancelled" at the console.
2 When you are ready, call us over to see your working program and code.
3 When you are ready, show us your modification.
Complete this program so that the file message is decryted so that you can read the message. To do this, open the same file (that is message) for low-level output and write the byte array to it, but you need to do something to each byte before (or as) you write back to the file. What are you going to have to do to get the correct character back?
4 When you are ready, show us the finished program.
Now uncomment the rest of the code in this file by taking out the line /* and also */. The code you uncommented, opens a DataInputStream to the file data. It reads an int, a boolean, and a double and writes them to the console using System.out.println(). Is the output what you expected? How does it compare to the contents of the data file?
5 When are ready with the answers to the above questions, call us
over and explain the results of running this program.
Now edit the class TextInAndOut in this same subdirectory. This program writes the same data to file data as text strings, and then reads the data back in using a DataInputStream and prints the values to the console. Try to run this program. What is the problem? Notice that an exception is thrown. Fix the program so that it reads the same int, boolean, and double that were written to the text file. Hint: Use a BufferedReader instead of a DataInputStream and convert input lines to the appropriate data types.
6 When are ready, call us over to explain the problem with the program
and show us your repair.
7 When are ready, call us over to explain the problem with this program
and how your fixed it so that when we run it, it creates a file
with instances of three kinds of objects.
In the same directory, edit the class FilterIntegers. This program opens the file objects.dat (the file that was created using the MakeFile program) and it is supposed to read all the objects from the file. If an object is an "instanceof" the Integer class, it should be counted (use variable count) and printed at the console. Finish the code to do this in the try block. About how many Integers do you expect there to be, given the number of objects in the file?
8 When are ready, call us over to
see your working FilterIntegers program. Be prepared to tell us
about how many Integers you expect to find and why.