{{theTime}}

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:

java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport

SpringBoot Error: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.j...