![]() |
VOOZH | about |
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.
Syntax:
public FileChannel getChannel()
Parameter: getChannel() method has no parameter.
Return Type: getChannel() method will return a unique FileChannel object.
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
Output:
Current size of the file is 48
Note: The programs might not run in an online IDE. Please use an offline IDE and change the Name of the file