Home »
Java programming language
Java FileInputStream getFD() Method with Example
FileInputStream Class getFD() method: Here, we are going to learn about the getFD() method of FileInputStream Class with its syntax and example.
Submitted by Preeti Jain, on April 01, 2020
FileInputStream Class getFD() method
- getFD() method is available in java.io package.
- getFD() method is used to return the FileDescriptor object that denotes the connection to the exact file in the file system being used by this FileInputStream.
- getFD() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- getFD() method does not throw an exception at the time of getting a file descriptor.
Syntax:
public FileDescriptor getFD();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of the method is FileDescriptor, it returns the same FileDescriptor object linked with this stream.
Example:
// Java program to demonstrate the example
// of FileDescriptor getFD() method
// of FileInputStream
import java.io.*;
public class GetFDOfFIS {
public static void main(String[] args) throws Exception {
FileInputStream fis_stm = null;
FileDescriptor file_desc = null;
try {
// Instantiates FileInputStream
fis_stm = new FileInputStream("C:\\includehelp.txt");
// By using getFD() method is to return
// FileDescriptor linked with the stream
file_desc = fis_stm.getFD();
System.out.println("fis_stm.getFD(): " + file_desc);
} catch (Exception ex) {
System.out.println(ex.toString());
} finally {
// with the help of this block is to
// free all necessary resources linked
// with the stream
if (fis_stm != null) {
fis_stm.close();
}
}
}
}
Output
fis_stm.getFD(): java.io.FileDescriptor@7bfcd12c