getChannel(): This method is available in the java.io.FileOutputStream class of Java.
Syntax:
FileChannel java.io.FileOutputStream.getChannel()
This method returns the unique FileChannelobject associated with this file output stream.
The initial position of the returned channel will be equal to the number of bytes written to the file unless this stream is in append mode, which will be equal to the size of the file.
Note:
1. Writing bytes to this stream will increment the channel's position accordingly.
Parameters: NA
Returns: the file channel associated with this file output stream.
Exceptions: NA
Approach
Java
import java.io.File;import java.io.FileOutputStream;import java.io.IOException;public class FileOutputStreamgetChannel {public static void main(String[] args) throws IOException {String pathname = "D:\\hello.txt";File file = new File(pathname);FileOutputStream fileOutputStream =new FileOutputStream(file);System.out.println(fileOutputStream.getChannel());fileOutputStream.close();}}
Output:
sun.nio.ch.FileChannelImpl@244038d0
No comments:
Post a Comment