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:

gradlew : The term 'gradlew' is not recognized as the name of a cmdlet, function, script file , or operable program

The command gradlew was not found, but does exist in the current location.  Windows PowerShell does not load commands from the current locat...