posted 21 years ago
For what it's worth, I think a lot of people here make changes to the file immediately. Most also read from the file every time a read() or find() is performed. Personally I keep everything in memory so that read() and find() don't need to bother the file - but on any update(), create() or delete() I also write the changes to the file right away. Otherwise you need to consider how and when will the updates be made to the file? There are certainly ways to do this, but there are possible complications too. I think it's a perfectly viable solution to read and write to the file as necessary.
File access is extremely slow and also very hard to make threadsafe..
FileChannel makes it much faster. There are several approaches to thread safety, which need not be very difficult at all really. And really, if you're keeping data in memory, shared by multiple threads, then you need to synchronize access to that memory. Which is no more or less difficult than synchronizing access to the file, I think. The only difference is that if the file access is slow, the synchronization may cause that slowness to affect other methods as well. But file access with FileChannel is not that slow, and efficiency isn't a big requirement for the assignment anyway.
"I'm not back." - Bill Harding, Twister