FileInputStream getChannel() Method in Java with Examples Last Updated : 16 Dec, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 return the FileChannel object that is associated with "this" FileInputStream instance.The channel position will change whenever we read bytes from this stream.Whenever the channel's position is changed, the stream's file position will also get changed.The number of bytes read from the file will determine the initial position of the returned channel. Syntax: public FileChannel getChannel() Parameter: getChannel() method has no parameter. Return Type: getChannel() method will return a unique FileChannel object. How to invoke getChannel() 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 unique FileChannel object associated with this fileInputStream, we will call the getChannel() method FileChannel fileChannel = fileInputStream.getChannel(); The below program will illustrate the use of the getChannel() method. Example: Program to get the FileChannel object and then to print the size of the channel's file Java // Java Program to demonstrate the working // of the FileChannel object and then to // print the size of the channel's file import java.io.*; // import FileChannel import java.nio.channels.FileChannel; 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 unique object of FileChannel for // this specified fileInputStream FileChannel fileChannel = fileInputStream.getChannel(); // print the current size of the channel's file System.out.println( "Current Size of the file is : " + fileChannel.size()); } catch (Exception exception) { System.out.println(exception.getMessage()); } } } Output: Current size of the file is 48tmp.txt Note: The programs might not run in an online IDE. Please use an offline IDE and change the Name of the file Comment More infoAdvertise with us Next Article FileInputStream available() Method in Java with Examples H harshsethi2000 Follow Improve Article Tags : Java Java-FileInputStream Practice Tags : Java Similar Reads FileInputStream getFD() Method in Java with Examples 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 wil 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 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 Like