OF FILES AND STREAMS
When Dealing with file reading and writing, several types of classes exist that can help you (and confuse you at the same time). Generally, the table below will show how you use the classes discussed in class.
Reading | Writing | Accessing a FileName | |
Text Files | Use DataInputStream (deprecated) see example | Use PrintStream see example | FileInputStream/FileOutputStream |
Objects (serialized) | Use ObjectInputStream *remember to type-cast as you read
your objects see example |
Use ObjectOutputStream see example |
FileInputStream/FileOutputStream |
Another way for reading text | BufferedReader (better than DataInputStream) see example | FileReader | |
Another way for writing text | PrintWriter see example | FileWriter | |
Dealing with Filenames | To open an existing filename, use FileInputStream("filename.txt") | To create a new file, use FileOutputStream("filename.txt") |
For more information, visit SUN's website containing SUN Documentation on Streams.