Home »
Java programming language
Java FileOutputStream getFD() Method with Example
FileOutputStream Class getFD() method: Here, we are going to learn about the getFD() method of FileOutputStream Class with its syntax and example.
Submitted by Preeti Jain, on April 01, 2020
FileOutputStream Class getFD() method
- getFD() method is available in java.io package.
- getFD() method is used to return the FileDescriptor object linked with this FileOutputStream that denotes the connection to the actual file in the file system.
- 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 may throw an exception at the time of returning the file descriptor.
IOException: This exception may throw when getting any input/output error while performing.
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 FileDescriptor object linked with this FileOutputStream.
Example:
// Java program to demonstrate the example
// of FileDescriptor getFD() method
// of FileOutputStream
import java.io.*;
public class GetFDOfFOS {
public static void main(String[] args) throws Exception {
FileOutputStream fos_stm = null;
FileDescriptor file_desc = null;
try {
// Instantiates FileOutputStream
fos_stm = new FileOutputStream("D:\\includehelp.txt");
// By using getFD() method is to return
// FileDescriptor linked with the stream
file_desc = fos_stm.getFD();
System.out.println("fos_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 (fos_stm != null) {
fos_stm.close();
}
}
}
}
Output
fos_stm.getFD(): java.io.FileDescriptor@7bfcd12c