|20-CS-694||Advanced Programming Techniques||Spring 2012|
This series shows how to use many of the classes associated with file
handling. Click on the class names in the following table to see class
Open and read a text file - token delimiters can be set by the user.
Edit the file and write it. Classes FileOutputStream and
FileWriter are used to write the file.
Download test1.fil and load it into the applet by clicking the 'Choose File' button to bring up a file-chooser, select the file from the chooser, and clicking the 'Read' button. Change the delimiter in the top right textfield and repeat to see the possible interpretations. Click 'Write' to write the file.
||-||Same as above except the PrintWriter class is used to write. The text file is test2.fil which contains a number of | and ? to try as delimiters.|
||-||Open, read, and write a binary random access file such as test3.fil. This illustrates the many methods of the RandomAccessFile class that support writing data in various ways. The test file test3.fil contains a sequence of ints.|
||-||Read and write class objects. In this example the test file test4.fil has two objects: the first is a hash table, the second is a vector with the hash table as element 3. The code finds the second object, invokes the elementAt method to get the hash table. Then invokes the get method on the hash table to get the hash table elements.|