Search This Blog

Total Pageviews

SeekableByteChannel example using FileChannel in Java

SeekableByteChannel: A Channel to read, write, map and, manipulate a file.  It has a current position within its file which can be both queried and modified.

        -- For huge files this is often much more efficient than invoking the usual read or write methods.

        -- Ensures the data is not lost in the event of a system crash.

        -- Very fast transfer directly to or from the filesystem cache.

        -- File channels are safe for use by multiple concurrent threads. Sample Program to use FileChannel to copy a File.
public class CopyFileChannel { public static void main(String str[]) throws IOException { /** Use try with resource feature to autoclose the FileChannel.*/
try (FileChannel inputChannel = new FileInputStream("Fromfile_PATH").getChannel()){                  try (FileChannel outputChannel = new FileOutputStream("Tofile_PATH").getChannel()){                 inputChannel.transferTo(0, inputChannel.size(), outputChannel);
                    }                }                  } }

No comments:

Could not find method signingConfigs() for arguments

Could not find method signingConfigs() for arguments [build_5dw7nwfc8ibd8sagvx4p79x1u$_run_closure5@13e86039] on root project 'android&#...