FileInputStream getFD() Method in Java with Examples Last Updated : 01 Dec, 2021 Comments Improve Suggest changes Like Article Like Report Java.io.FileInputStream.getFD() method is a part of Java.io.FileInputStream class. This method will return the FileDescriptor object associated with the file input stream. getFD() method is declared as final that means getFD() cannot be overridden in the subclassesFileDescriptor object that we will get using getFD() method will represent the connection to the actual file in the file systemgetFD() method might throw IOException. Syntax: public final FileDescriptor getFD() throws IOException Return Type: getFD() method will return the instance of FileDescriptor associated with this FileInputStream. Exception: getFD() method might throw IOException if any Input/output exception raises. How to invoke getFD() method? Step 1: First, we have to create an instance of Java.io.FileInputStream class FileInputStream fileInputStream =new FileInputStream("tmp.txt"); Step 2: To get the instance of FileDescriptor associated with this fileInputStream, we will invoke the getFD() method FileDescriptor fileDescriptor =fileInputStream.getFD();Example: Java Program to get an instance of FileDescriptor and then to check it is valid or not In the below program, we will use Java.io.FileInputStream.getFD() method to get the object of FileDescriptoruse FileDescriptor valid() method to check if the instance of the file descriptor is valid or not Java // Java Program to get an instance // of FileDescriptor and then to // check it is valid or not import java.io.*; class GFG { public static void main(String[] args) { try { // create instance of FileInputStream class // user should change name of the file FileInputStream fileInputStream = new FileInputStream( "C://geeksforgeeks//tmp.txt"); // if the specified file does not exist if (fileInputStream == null) { System.out.println( "Cannot find the specified file"); return; } // to get the object of FileDescriptor for // this specified fileInputStream FileDescriptor fileDescriptor = fileInputStream.getFD(); // check if the fileDescriptor is valid or not // using it's valid method // valid() will return true if valid else false System.out.println("Is FileDescriptor valid : " + fileDescriptor.valid()); // will close the file input stream and releases // any system resources associated with the // stream. fileInputStream.close(); } catch (Exception exception) { System.out.println(exception.getMessage()); } } } Output: Is FileDescriptor valid : truetmp.txt Note: The programs will run on an online IDE. Please use an offline IDE and change the Name of the file according to your need. Comment More infoAdvertise with us Next Article FileInputStream getFD() Method in Java with Examples harshsethi2000 Follow Improve Article Tags : Java Java-FileInputStream Practice Tags : Java Similar Reads FileInputStream getChannel() Method in Java with Examples The getChannel() method is a part of Java.io.FileInputStream class. This method will return the unique FileChannel object associated with the file input stream. A channel obtained from the getChannel() method of the Java.io.FileInputStream instance will be "open for reading."getChannel() will retur 2 min read FileInputStream skip() Method in Java with Examples FileInputStream class is quite helpful to read data from a file in the form of a sequence of bytes. FileInputStream is meant for reading streams of raw bytes such as image, audio, video, etc. For reading streams of characters, FileReader is recommended. It was firstly introduced in JDK 1.0. FileInpu 4 min read FileInputStream close() Method in Java with Examples FileInputStream class is helpful to read data from a file in the form of a sequence of bytes. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. FileInputStream.close() method After any operation to the file, w 2 min read FileInputStream available() Method in Java with Examples The available() method of FileInputStream class is used to return the estimated number of remaining bytes that can be read from the input stream without blocking. This method returns the number of bytes remaining to read from the file. When a file is completely read, this function returns zero. Synt 3 min read Java FileInputStream read() Method with Examples FileInputStream class in Java is useful to read data from a file in the form of a sequence of bytes. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. The read() method of InputStream class reads a byte of data 3 min read File isFile() method in Java with Examples The isFile() function is a part of File class in Java. This function determines whether the is a file or Directory denoted by the abstract filename is File or not. The function returns true if the abstract file path is File else returns false. Function signature: public boolean isFile() Syntax: file 2 min read Java FileReader Class getEncoding() Method with Examples The getEncoding() method of FileReader Class in Java is used to return the name of the current stream's character encoding. If the stream is utilizing a historical encoding name, it will be returned; otherwise, the canonical encoding name of the stream will be returned. Syntax: public String getEnco 2 min read Files copy() Method in Java with Examples The copy() method of java.nio.file.Files Class is used to copy bytes from a file to I/O streams or from I/O streams to a file. I/O Stream means an input source or output destination representing different types of sources e.g. disk files. Methods: Based on the type of arguments passed, the Files cla 5 min read File canRead() method in Java with Examples The canRead()function is a part of the File class in Java. This function determines whether the program can read the file denoted by the abstract pathname. The function returns true if the abstract file path exists and the application is allowed to read the file.Function signature: public boolean ca 2 min read Java FileReader Class read() Method with Examples The read() method of FileReader class in Java is used to read and return a single character in the form of an integer value that contains the character's char value. The character read as an integer in the range of 0 to 65535 is returned by this function. If it returns -1 as an int number, it means 2 min read Like