Java FileOutputStream getFD() Method
Example
Check if the file descriptor is valid, before and after the stream is closed:
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
FileOutputStream output = new FileOutputStream("filename.txt");
FileDescriptor fd = output.getFD();
System.out.println(fd.valid());
output.close();
System.out.println(fd.valid());
}
}
Definition and Usage
The getFD() method returns the FileDescriptor object of the stream. A file descriptor is the number or handle that the system uses for an open file.
Beginners rarely need it. Its valid() method returns true while the file is open.
Tip: Call output.getFD().sync() to make sure that all written bytes are saved on the disk.
Syntax
public final FileDescriptor getFD()
Parameter Values
None.
Technical Details
| Returns: | The FileDescriptor object of the stream. |
|---|
Related Pages
Java FileOutputStream Tutorial
❮ FileOutputStream Methods