Rollerball
Rollerball

Reputation: 13118

Creating a FileReader with a FileDescriptor what for?

From the official API:

Do you know any real case where the following constructor would be actually useful? FileReader

public FileReader(FileDescriptor fd)

Creates a new FileReader, given the FileDescriptor to read from.

Parameters:
    fd - the FileDescriptor to read from

Thanks in advance.

Upvotes: 0

Views: 417

Answers (1)

Holger
Holger

Reputation: 298489

There are two uses:

  1. Access to the standard streams, e.g.

    FileWriter fw=new FileWriter(FileDescriptor.out);`
    
  2. Access to the same file of an existing stream, e.g.

    FileInputStream is= … ;
    FileReader r=new FileReader(is.getFD());
    

    This works even with having reading and writing streams on a file at the same time. You can also create streams or readers/writers to an existing RandomAccessFile. Unfortunately, FileReader and FileWriter lack the getFD() method which the other classes have.

Upvotes: 1

Related Questions