well, it's really not necessary to go thru the trouble of setting up a
isReadable() method... in fact, from what you have described, i'd be
inclined to advise against it, unless you want to maintain static /
post-mortem data...
for you see, the java i/o libraries have all the "isReadable"
functionality you could ever imagine. and should a file be altered or
damaged or never properly written in the first place, java is more than
capable of detecting something wrong depending on the level of
sensitivity you are interested in.
for simplicity in your design, you should store and retrieve data as
objects as a preference with any object oriented langauge. unless your
application is importing or exporting data this ought to be the default.
the reason being due to the excellent design put into saving objects as
well as detecting any changes to the object image on the restore.
now by objects, i am referring to the Object streaming classes and not
so much a vendor of object databases.
now for whatever reason you should be interested in investigating a
corrupted object stream, you have the flexibility of opening the same
file/stream with a lower level protocol, say a data stream. this will
allow you to examine the bytes without throwing higher level exceptions
finally, the exception mechanism became a main stream procedure in the
object design community for a reason.... namely simplicity in design
with respect to error management. the phylosophy of exceptions is that
you are separating error detection from error handling. this was a major
breakthrew in code design as it allowed developers of commercial
frameworks (or simply previous projects) to identify errors and allow
future programmers to be able to handle future error handling needs
without out having to "change" the origional code.... a lesson well
learned from the days of spagetti design...
i hope this helped
- perry
Jole wrote:
Hi
I'm writing a program that needs to read from a file. In order for the
program to be robust, it should somehow check that the file isn't corrupt,
or stuffed in any way. For example, that file may have been created but a
crash occurred at that point in time (while it was being created), damaging
the file. Now, my program which needs to read from this file, should first
check that it's in good condition, and that it hasn't been stuffed up in
any way. What is the normal way of doing this?
thanks in advance
Jole
I'm using Java and am aware of some of those File.XX methods. perhaps the
File.isReadable() methods will fail if the files have been damaged or
corrupted? or another way ?