If there is a class that does all you need and a class that does that and more its "better programming" to use the simpler one
also FileDecriptor will provide the same interface for an open File, an open Socket or any othet source or sink of bytes. so you could use the same class for all these rather than separate classes for each type of stream (basic principal of OOP, make things act as similar as possible)
Thank you very much!!!
So you mean that FileDescriptor can stand for ANY OS object (like socket, devices, like printer) and File Object doesn't..OK i got the difference... but What's the use of FileDescriptor?
u said that i provides same interface.. but where is the interface.?. there are only two methods.. sync and valid().. use can't use FileDescriptor to do any operations on the object then what's the use?
I am sorry if i am too much silly!! but i am new to Java...:)
Hi!
As long as I know, the main use of a FileDescriptor is to ensure the flushing of file buffers to disk by using the sync() method.
It is, if you have a FileOutputStream (or any stream connected to it) you cannot be sure that calling the flush() method will flush O.S. buffers to disk. The only way to do that is by means of:
FileOutputStream out = new FileOutputStream( "xxx.yyy" );
.... // write here your data
// The following only flushes FileOutputStream buffers (if any)
out.flush();
// Try to flush O.S. buffers
out.getFD().sync();
Take a look at "JAVA I/O" by E. R. Harold for more info.
Bye.