Java FileInputStream getFD() Method
Example
Check if the file descriptor is valid, before and after the stream is closed:
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
FileWriter myWriter = new FileWriter("filename.txt");
myWriter.write("Hello World");
myWriter.close();
FileInputStream input = new FileInputStream("filename.txt");
FileDescriptor fd = input.getFD();
System.out.println(fd.valid());
input.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.
Syntax
public final FileDescriptor getFD()
Parameter Values
None.
Technical Details
| Returns: | The FileDescriptor object of the stream. |
|---|
Related Pages
❮ FileInputStream Methods