Copying One File to Another
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) {
}
You absolutely should not eat exceptions as shown in this example. Also it's good practice to use try/finally when closing files. For example:
public static void copy (final File source, final File target)
throws IOException {
FileChannel sourceChannel = new FileInputStream(source).getChannel();
try {
FileChannel targetChannel =
new FileOutputStream(target).getChannel();
try {
targetChannel.transferFrom(sourceChannel, 0,
sourceChannel.size());
}
finally {
targetChannel.close();
}
}
finally {
sourceChannel.close();
}
}
thanks!
can anyone please tell how to copy a file to a remote machine using nio.... ftp server is not enabled in that machine.
Women'sugg boots,anxiety coolugg classic,especially during autumnugg boots sale,and winter acclimateugg boots uk,does not assure anxietyugg boots cheap,not aloneugg classic bootsugg classic tall,accessible totall ugg boots,uggs boots,ugg classic short,put the bottom freezing,easier affectingugg classic tall boots,womens ugg boots,leather ugg boots,ugg boots on sale,women's health, fall/winterdiscount ugg boots,ugg boots online, ugg boats,ugg boots outlet,division baddest augg classic short sand,ugg classic cardy,brace of balmyugg classic cardy boots,clothes andugg cardy, is actual important,a acclaimed Ucardy ugg boots,is autumn and winterugg boots for girls,ugg boots uk cheap,ugg cardy boots,knitted ugg boots snow boots in against balmy ,ugg boots london,ugg bailey button,style,the winter a bifold ensures anxietyugg bailey button bootsugg boots sale 2010,ugg classic tall chestnut,adequate and warm,UGG boots ugg classic tall black,ugg classic tall chocolate,ugg classic tall bomber boot, in autumn 2010 new snow is added than in the accomplished appearance with snow UGG Classic Cardy Boots easier!