I looked through the instructions from sun and it doesnt say anything specifically about writing the database back to file once you read it in. Dunno about your instructions, but mine said the following, under the "User Interface" section:
It must allow the user to book a selected record, updating the database file accordingly.
I'd imagine most assignments are similar in this respect. The question is though -
when do you write to the file? The two major possibilities are (a) once when you close the DB, or (b) every single time a change is made. If you're using a DataOutputStream, the latter may sound unreasonable - why rewrite the entire DB file contents every time a change is made? But if you look at using a RandomAccessFile or FileChannel instead, you can usually write
just the changed record to the approriate part of the file. You don't need to touch the majority of the file. In this case, option (b) is much more reasonable. And you don't have to worry so much about what happens if the server dies without a proper shutdown, because the file contents will still reflect the most up-to-date version of the data.
Well, if the server dies there are still strange things that could happen, and you aren't really expected to worry about all these possibilities for this assignment. But the point is, writing the changed records as they occur will significantly reduce the risk of these problems.
Note that RandomAccessFile has many of the same methods that you're using in the DataOutputStream. (Check out the DataOutput interface which defines these.) The different is, RAF allows you to seek() a particular position of the file before you start writing.
It's definitely possible to write your records correctly using various writeXXX() methods of RAF. However you need to be careful and read just what each of the method you use really does. In particular, for reading and writing Strings, neither writeChars() nor writeUTF() matched the required file format. Not exactly. Read the API carefully to see why. Consider using the methods that read and write a byte[] array instead, and figure out how to convert between a byte[] and a
String. (The String class has all the methods you need.)
It's also possible to do all this with a FileChannel reading and writing a ByteBuffer. If that makes sense to you, go for it. But it's probably easier to use the RAF methods, so I'd work on that first.