getChannel(): This method is available in the java.io.FileInputStream class of Java.
Syntax:
FileChannel java.io.FileInputStream.getChannel()
This method returns the unique FileChannel object associated with this file input stream.
The initial position of the returned channel will be equal to the number of bytes read from the file so far. Reading bytes from this stream will increment the channel's position.
Changing the channel's position, either explicitly or by reading, will change this stream's file position.
Parameters: NA
Returns: the file channel associated with this file input stream.
Exceptions: NA
Approach
Java
import java.io.File;import java.io.FileInputStream;import java.io.IOException;public class FileInputStreamgetChannel {public static void main(String[] args) throws IOException {String pathname = "D:\\hello.txt";File file = new File(pathname);FileInputStream fileInputStream = newFileInputStream(file);System.out.println(fileInputStream.getChannel());fileInputStream.close();}}
Output:
sun.nio.ch.FileChannelImpl@244038d0
No comments:
Post a Comment