Question

What's the use of the FileDescriptor class in Java ? We can only obtain it with the getFD() methods on streams and then we can use the obtained FD to create another instance of, say, FileInputStream which we can also do by creating a FileInputStream object with the same file name (instead of using its FD).

Also, the methods in, out and err. what use can they be put to ?

Was it helpful?

Solution

As the JavaDoc says:

Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes. The main practical use for a file descriptor is to create a FileInputStream or FileOutputStream to contain it.

Applications should not create their own file descriptors.

They are therefore a behind-the-scenes implementation detail for the JDK to plug in to the underlying OS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top