|
How to copy one file to another through channel |
|
|
This Java tips illustrates a method of copying one file to another file through channel.
A channel is created both on source as well as destination and then the file is
copied between those two channels.
try {
// Create channel on the source
FileChannel srcChannel =
new FileInputStream("srcFilename").getChannel();
// Create channel on the destination
FileChannel dstChannel =
new FileOutputStream("dstFilename").getChannel();
// Copy file contents from source to destination
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
// Close the channels
srcChannel.close();
dstChannel.close();
} catch (IOException e) {
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.