How to create a copy of a file

Is there a method in Java API with which I can create a copy of a file (like running "copy" or "cp" at system command prompt), so that I don't have to use InputStream and OutputStream and create the new file byte by byte?

I would never create an array with the size of the input file. What do you do, if the file is 2GB?
I'd rather use buffered streams: BufferedInputStream in = new BufferedInputStream(new FileInputStream("inputfile.dat"));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("outputfile.dat"));
byte[] buffer = new byte[4096];
int b = in.read(buffer);
while(b>=0)
  out.write(buffer, 0, b);
  b = in.read(buffer);
in.close();
out.close();I'm not sure if using an array to read from a BufferedInputStream really improves performance, but you can play around with it. If you know you have big files, you might want to play with the size of the buffer for the streams as well and see how it affects read/write performance. Setting a larger buffer then the default 64K for the output stream might speed up things.
Thomas

Similar Messages

  • How to create a table in the file using java code.?

    HI,
    I should export the data from the view objects to a word document. I have done that but I should
    display the data in the form of a table.
    Kindly come up with the necessary information on how to create a table in the file using java.
    Thanks,
    Phani

    Hi, Thank you for responding to my query.
    The below are the details of my code.
    DCBindingContainer dcBindings =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding StudentDetailsContent =
    (DCIteratorBinding)dcBindings.get("StudentView1Iterator");
    OutputStreamWriter w = new OutputStreamWriter(outputStream, "UTF-8");
    Row currentRow =
    StudentDetailsContent.getRowSetIterator().first();
    Object a[]= currentRow.getAttributeValues();
    int i;
    for(i=0 ;i<=a.length;i++){
    w.write(a.toString());
    w.write(" ");
    w.flush();
    I am usning this coding to achieve the task of exporting data to file.
    I need to display this information in the table that is where I need help from you people.
    Thanks,

  • How to create Inbound Idoc from XML file-Need help urgently

    Hi,
    can any one tell how to create inbound Idoc from XML file.
    we have xml file in application server Ex. /usr/INT/SMS/PAYTEXT.xml'  we want to generate inbound idoc from this file.we are successfully able to generate outbound XML file from outbound Idoc by using the XML port. But not able to generate idoc from XML file by using we19 or we16.
    Please let me know the process to trigger inbound Idoc with out using  XI and any other components.
    Thanks in advance
    Dora Reddy

    Hi .. Did either of you get a result on this?
    My question is the same really .. I am testing with WE19 and it seems SAP cannot accept an XML inbound file as standard.
    I see lots of mention of using a Function Module.
    Am I correct in saying therefore that ABAP development is required to create a program to run the FM and process the idoc?
    Or is there something tht can be done with Standard SAP?
    Thanks
    Lee

  • SMARTFORM: how to create 3 copy (each copy can print more than one page)

    SMARTFORM: how to create 3 copy (each copy can print more than one page)
    Hello everyone.
    my user want to have form that print 3 copy.
    such as 1 copy description = master,  2 copy description = copy 1 ,3 copy description = copy 2.
    so i create 3 page . I copy from page 1.
    and in each page there is main window which can have data more than 1 page.(such as have a lot of sale data ,it's take 2 page for show output .so it's take 2 page in each copy)
    please help me.
    how to set page and window in each page for print 3 copy and each page can have main window that print more than 1 page

    Hello Vinit.
    thank you very much for your help.
    could you help me more please.
    in below code
      DO NAST_ANZAL TIMES.
    l_counter = l_counter + 1.  " << pass this to FM and use for the TEXT to print
    CALL FUNCTION LF_FM_NAME
               EXPORTING
                         COUNTER = l_COUNTER   " USE this to derive the text into PRINTOUT
    enddo.
    Now i out of office .so i cannot test.
    where do i set NAST_ANZAL for 3 ?
    can i input ?
    NAST_ANZAL = 3.
      DO NAST_ANZAL TIMES.
    l_counter = l_counter + 1.  " << pass this to FM and use for the TEXT to print
    CALL FUNCTION LF_FM_NAME
               EXPORTING
                         COUNTER = l_COUNTER   " USE this to derive the text into PRINTOUT
    enddo.
    Edited by: dittaporn nanasilp on Mar 12, 2011 3:33 PM

  • Finder is creating "conflicted copy"s of files.  What is this all about?

    My finder is creating "conflicted copy"s of files on our network. We have 9 mac's (a law firm) and it appears that when another person opens a file, Mac sometimes creates a "conflicted copy".  does anyone know why this is happening and what I can do to prevent  this?  I like nice neat folders and files and this is messin with my mojo!
    Thank you!
    Guy Vitetta
    Charleston SC

    The what is happening is that you are editing the files at two locations but Dropbox isn't syncronising them and ends up with two different copies.
    Regards,
    Shawn

  • How to create and manage the log file

    Hi,
    I want to trace and debug the program process.
    I write the code for creating log file and debugging the process.
    But i am not able get the result.
    please help me how to create and manage the log file.
    Here i post sample program
    package Src;
    import java.io.*;
    import org.apache.log4j.*;
    import java.util.logging.FileHandler;
    public class Mylog
         private static final Logger log = Logger.getLogger("Mylog.class");
         public static void main(String[] args) throws Exception {
         try {
           // Create an appending file handler
            boolean append = true;
            FileHandler handler = new FileHandler("debug.log", append);
            // Add to the desired logger
            Logger logger = Logger.getLogger("com.mycompany");
            System.out.println("after creating log file");     
              catch (IOException e)
                   System.out.println("Sys Err");
            }Please give the your valuable suggesstion... !
    Thanks
    MerlinRoshina

    Just i need to write a single line in log file.

  • How to create a copy of a project

    We are using RoboHelp HTML version X5, and we use version
    control. We are trying to figure out how to create a copy of a
    project so we can edit the new version with the old version
    remaining intact. That way we could have multiple versions of our
    help system, a distinct version for each software release we have.
    Thanks.

    The way I do it is rather simple.
    1.       Copy the local RoboHelp project to a new location.
    2.       Remove the link to source control. (See http://www.robowizard.com/RoboWizard/MonthlyScry/102004.htm on how to do this without opening RoboHelp. Please follow these instructions.)
    3.       Open the RoboHelp project and add it to source control as a new project.
    By creating a copy of the entire project directory, ALL the content is retained.
    Greet,
    Willam

  • How to create new Sheet in Excel file and write into it

    Hi to all, my requirement is this:
    I have an excel file (.xls) with multiple sheets (three sheets for precision: sheet1, sheet2 and sheet3).
    I must create in the same excel file new sheet, say sheet4, read data from sheet1, sheet2 and sheet3 and write them into sheet4.
    How to realize this in SSIS?
    Expecially, Is it possible to realize this in SSIS?
    thanks in advance.

    You need to create the sheet with the required metadata. There's no use creating blank sheet.
    Also metadata has to be fixed using a sample sheet prior to start of the package for setting the mapping. You may create a excel template for this purpose to just set the mapping at design time.
    At runtime pass actual excel sheet path for ExcelFilePath property of the source to point to correct file.
    Also the create table statement should include the same metadata info (columns)
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    Hi, well it works fine! I have used a sample sheet prior to start of the package for setting the mapping.
    Next at run time  pass actual excel sheet path for ExcelFilePath property of the source to point to correct file.
    However I have set also ValidateExternalMetadata properties of the Excel Destination to false and DelayValidation properties of the package to true.
    Now my problem is the following:
    I stored the three sheets name (sheet1, sheet2, sheet3) in the Object type user variable through a script task and the foreach loop loops through the three sheets stored in the variable.
    Now, I want that at each iteration the CURRENT VALUE of the Object type user variable is mapped into another user variable wich in turn is given in input to the Excel Source.
    Resuming:
    -) I have to copy the content of three sheets (sheet1, sheet2, sheet3) of excel file into another new sheet,   sheet4.
    -) I stored the three sheets name (sheet1, sheet2, sheet3) in the Object type user variable.
    -) With a  foreach loop container I loops the three sheets stored in the Object type user variable.
    -) Within a foreach loop container I have a Data Flow Task that transfer data from source sheet (sheet1, sheet2, sheet3) into destination sheet, sheet4.
    -) PROBLEM: how to change dinamically at each iteration of the foreach loop the name of source sheet? In the destination excel Task the sheet is always the same at each iteration, sheet4. But in the source excel task the name of sheet musts change at each
    iteration. In particular at the first iteration the name of the source sheet must be "sheet1$", at the second iteration "sheet2$", in the last iteration "sheet3$".
    How to change sheet name dinamically at each iteration?
    thanks.

  • How to create multiple copies of a file with renamed filenames

    hi,
     I want to create multiple copes of a  file [ say abc.docx] which has 3.5 MB of size  and want to rename it through power shell.
    so, in the end, i want to get abc_1.docx,abc_2.docx, abc_3.docx ....abc_10.docx in the same folder with the same size. i mean, after running the ps script i should get the foldwer size set to 35 MB .
    can anyone help, how to achieve this?
    I am newbie in powershell. 
    i tried the below :
    $File = Get-ChildItem -Path "D:\ABCFolder\" -Filter Copying.bat -Recurse
    for($i = 0; $i -lt $File.Count; $i++)
    Copy-Item $File[$i].FullName ("D:\ABCFolder\" + $File[$i].BaseName + $i +".doc")
    help is appreciated!

    but the below one didnt work:
    $File = Get-ChildItem -Path "D:\ABCFolder\" -Filter Copying.Bat -Recurse
    for($i = 0; $i -lt $File.Count; $i++)
    1..10 | Copy-Item $File[$i].FullName "$($File[$I].DirectoryName)\$($File[$i].BaseName)_$_$($File[$i].Extension)"
    am getting the below erro when executing this code:
    $File = Get-ChildItem -Path "D:\mfolder\"
    $count = $file.Count
    for ($x = 0; $x -lt $count; $x++)
    $ext = $file[$x].Extension$name = $file[$x].BaseName
    for($i = 0; $i -lt 100; $i++)
    Copy-Item $File[$x].FullName -destination "D:\mfolder\$name_$i$ext"
    /////////////////////////////error below://///////
    At D:\mfolder\createcopies2.ps1:7 char:27
    + $ext = $file[$x].Extension$name = $file[$x].BaseName
    + ~~~~~
    Unexpected token '$name' in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

  • How to create Blu-Ray from previous files?

    Back in November of 2010 thefifthlion posted a similar question, but the thread was archived so I could not post a follow up in that same thread.
    My question is similar:  how to create a Blu-Ray from previous Compressor files.  His answer was to create a disc image by selecting "Hard Drive" from the Output Device pop up menu.  Then use Toast or Disc Utility to burn the copies.  Fine, but here's my revised question to that:
    Compressor just spent nearly 20 hours compressing a 2+ hour video with "Create Blu-Ray" selected for the When Job Completes.  Before it completed the Blu-Ray burner apparently fell asleep or went offline somehow because the computer wouldn't recognize the drive by the time Compressor was done.  So I had no choice but to selct "Cancel Burn" and stop the process, restart the computer, and get the Blu-Ray burner back online.
    You probably know where I'm going with this.  I now have two files on my desktop - the video and the audio file created of the project from Compressor.  BUT WHAT CAN I DO WITH THOSE FILES NOW?  Needless to say I don't want to go through the entire 20 hour process again - only to have the same thing happen with the burner drive.  As per the below paragraph (copied from thefifthlion's original post in November) is this the best way to burn Blu-Rays in Compressor?  Always create a disc image rather than burn right away... and then use a third party burner like Toast 10 or Disc Utility to burn the disc?  I can't believe Compressor doesn't have an option to open the project again and burn a Blu-Ray straight away.
    > Output Device pop-up menu: Use this pop-up menu to choose the device to format to. The pop-up menu displays a list of your system’s suitable output devices, including optical drives and the computer’s hard disk. Each device also includes the words Blu-ray or AVCHD to indicate which type of disc it creates. Choose Hard Drive to create a disk image (.img) file that you can burn to Blu-ray Disc media at a later time using the Disk Utility application (available in the Utilities folder). Other settings may change depending on the device you choose.
    Thanks very much for any feedback.
    Eric

    Follow up question:
    I went through the process again (approx 20 hours!! ) and this time made the video a disc image.  I don't have Toast (though I think it might be time to get it) but I keep reading that Disc Utility can burn a Blu Ray using that disc image.  So, I went through another multi hour process to burn that 20+ gig file onto a Blu Ray, but it appears that it didn't burn it as a playable disc, rather, more like it put the file on the disc as data files.  All the info is there, 20 some gigs, I can see all the files, but the disc doesn't play.
    Now I apologize if it's a silly question if it's known that you can't make a playable blu ray with Disc Utility, but I don't know either way, that's just what I've read and this is the first time I've tried it. 
    Soooooooo, if I always make a disc image, should I just get Toast and use that to make the blu ray?
    By the way, a brief update:  the whole reason this thread came up was because my Pioneer blur ray burner goes offline (sleep) after an hour or so and doesn't come back or wake up.  So with a long processing time in Compressor the drive goes offline and then can't burn the disc, so I lose that whole session.  Turns out that Pioneer (by their own admission) is not made to be fully compatible with Macs!!  In particular Mac Pros.  I took that drive out and replaced it with an LG.  Haven't tested it yet but I'm looking forward to it.
    Eric

  • How to create exact copy of a table

    Hello,
    I must admit my "google skills" have failed me and it is possible that I might be missing something obvious here but allow me to explain.
    If I have a table that is populated/accessed by a typical OLTP application such that over time the data in the table may become "fragmented".
    I know that is a very controversial term I used but that is not the question here. A simple way to describe the state of the table might be
    that the table has always been populated with lots of small INSERTs, modified with lots of small UPDATEs and data has been deleted in small DELETEs.
    This has meant that the data is neither closely stored in data blocks nor is in any particular order (so there are some empty blocks under HWM).
    Now my question is how do I create exact copy of this table and its indexes AS THEY EXIST AT THE MOMENT that includes
    1) its data
    2) its constraints/indexes etc.
    3) its storage parameters
    4) data stored in EXACTLY same manner as in original table.
    To avoid complications, the table in question is just a normal heap table without any partitioning involved. While CREATE TABLE AS SELECT (or CREATE
    TABLE followed by INSERT) will take care of points (1) to (3) above, it will not achieve point (4) above.
    Can somebody please help?
    Thanks in advance.

    Exp/Imp...
    C:\Windows\system32>expdp scott/tiger dumpfile=scottemp.dmp directory=DATA_PUMP_DIR tables="emp" constraints=y indexes=y statistics=y
    Export: Release 11.2.0.1.0 - Production on Sat Nov 24 15:35:34 2012
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Legacy Mode Active due to the following parameters:
    Legacy Mode Parameter: "constraints=TRUE" Location: Command Line, ignored.
    Legacy Mode Parameter: "indexes=TRUE" Location: Command Line, ignored.
    Legacy Mode Parameter: "statistics=y" Location: Command Line, ignored.
    Legacy Mode has set reuse_dumpfiles=true parameter.
    Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** dumpfile=scottemp.dmp directory=DATA_PUMP_DIR tables=emp reuse_dumpfiles=true
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 64 KB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
    Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    . . exported "SCOTT"."EMP"                               8.570 KB      14 rows
    Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
    Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
      E:\APP\SERVERROOM\ADMIN\ORCL\DPDUMP\SCOTTEMP.DMP
    Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 15:35:38
    C:\Windows\system32>impdp scott/tiger dumpfile=scottemp.dmp directory=DATA_PUMP_DIR tables="emp" constraints=y indexes=y statistics=y logfile=log.txt remap_schema=scott:hr
    Import: Release 11.2.0.1.0 - Production on Sat Nov 24 15:48:20 2012
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Legacy Mode Active due to the following parameters:
    Legacy Mode Parameter: "constraints=TRUE" Location: Command Line, ignored.
    Legacy Mode Parameter: "indexes=TRUE" Location: Command Line, ignored.
    Legacy Mode Parameter: "statistics=y" Location: Command Line, ignored.
    Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
    Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/******** dumpfile=scottemp.dmp directory=DATA_PUMP_DIR tables=emp logfile=log.txt remap_schema=scott:hr
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "HR"."EMP"                                  8.570 KB      14 rows
    Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
    ORA-39083: Object type REF_CONSTRAINT failed to create with error:
    ORA-00942: table or view does not exist
    Failing sql is:
    ALTER TABLE "HR"."EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFERENCES "HR"."DEPT" ("DEPTNO") ENABLE NOVALIDATE
    Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    Job "SCOTT"."SYS_IMPORT_TABLE_01" completed with 1 error(s) at 15:48:22
    C:\Windows\system32>sqlplus hr/hr
    SQL*Plus: Release 11.2.0.1.0 Production on Sat Nov 24 15:48:32 2012
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select * from emp;
    ...Result is there.
    14 rows selected.
    SQL>
    ORA-39083: Object type REF_CONSTRAINT failed to create with error:
    ORA-00942: table or view does not exist
    are understandable.Regards
    Girish Sharma

  • How to create an application-specific policy file?

    Hi Everybody:
    I'm a .NET developer with C #. I have a few applications currently running on my computer using the ODP 10.1
    Two weeks ago I installed on my computer the ODP 10.2 Release & now my previous applications have stopped working: when I try to make the connection to the database gives me this exception:
    OraOLEDB (0x80004005)
    ORA-12154: TNS: could not resolve the connect identifier specified
    In FAQ section for ODP.NET I found the next:
    Q: I have two .NET applications on the same machine running two different versions of ODP.NET. How do I ensure both these applications use the correct ODP.NET version?
    A: Beginning with ODP.NET 10.1.0.3, the Oracle installer will register the following publisher policy DLLs in the Global Assembly Cache (GAC) that redirect 9.2, 10.1 and 10.2 ODP.NET applications to use the last installed version of ODP.NET: Policy.9.2.Oracle.DataAccess.dll and Policy.10.1.Oracle.DataAccess.dll.
    ODP.NET 9.2 includes just the first policy DLL above. These policy files ensure that all your ODP.NET applications use the most recently installed version of ODP.NET.
    You may undo the redirection manually. Policy DLLs can be de-installed through gacutil.exe using the /u option. Another approach is to navigate to the GAC directory (i.e. C:\WINNT\assembly) through the Windows Explorer and delete the policy folders. That will eliminate any policy enforcement for all your ODP.NET applications.
    If you have applications on the same machine using different ODP.NET versions, you should create an application-specific policy file.
    I'm trying to do that, but I don't know what is an application-specific policy file. Someone can give me an example of How can I create and application-specific policy file???
    Regards

    Hi,
    Binding redirection is a ".net thing" as opposed to a "odp.net thing", see if this helps:
    http://msdn.microsoft.com/en-us/library/7wd6ex19(VS.71).aspx
    Hope it helps,
    Greg

  • How to create a header in csv file

    I´m still newbie in Labview, I just learnt it this week..
    I want to make a data translation for temperature sensor..
    I´m having trouble to create a header in csv file,can anybody help me ?
    I also attach my csv file, what I wanted to make is like this :
    dt ( ms )
    channel 0
    channel 1
    channel 2
    0,1
    1
    2
    3
    0,2
    4
    5
    6
    0,3
    7
    8
    9
    0,4
    10
    11
    12
     I also want to know how to make the time count from 0 not from the real time..
    Solved!
    Go to Solution.
    Attachments:
    my block diagram.jpg ‏266 KB
    my csv file.jpg ‏508 KB

    I already solve the problem, It´s quite confusing, I must use ; instead of \t at the delimiter.
    I have another question to ask :
    - When I start the program,can I make the dt(ms) count from 0 ? What I can do is using the Format/Date time string, I don´t want the time count based on the real time.
    This is what I made
    dt(ms)
    Ch0
    10:04:2012  13:12:06,871
    24,139404
    10:04:2012   13:12:08,924
    23,773193
    10:04:2012   13:12:08,925
    23,132324
    10:04:2012   13:12:08,926
    22,918701
    What I want is like this :
    dt(ms)
    Ch0
    0
    24,139404
    0,01
    23,773193
    0,02
    23,132324
    0,03
    22,918701
    Thx for the helps..
    Regards
    Citras
    Attachments:
    test_temp.vi ‏25 KB

  • How to create a folder in the file system?

    Hi All,
    How to create a normal folder in my PC's file system in a specific path?

    Host just passes commands to the OS; the simplest way to try would be playing a little bit around in the shell to figure out what's not working...
    C:\>dir "I am"*
    Volume in drive C is System
    Volume Serial Number is 5C03-B54D
    Directory of C:\
    File Not Found
    C:\>cmd /c mkdir "c:\I am a directory"
    C:\>dir "I am"*
    Volume in drive C is System
    Volume Serial Number is 5C03-B54D
    Directory of C:\
    09/21/2010  02:38 AM    <DIR>          I am a directory
                   0 File(s)              0 bytes
                   1 Dir(s)     509,628,416 bytes free
    C:\>cmd /c mkdir "c:\I am a directory"
    A subdirectory or file c:\I am a directory already exists.
    C:\>or with the host built-in
    host('cmd /c mkdir "'||full_path||'"');But first you should check if the directory already exists as mkdir will throw an error if it exists as you can see.
    cheers

  • How to save a copy of a file to different location using jfilechooser

    hi, this is ravikiran,
    In my project there is a situation where when a user clicks on some button, a copy of a file(which is initially in my project folder) must be saved to a location specified by the user.
    I have no idea how to do this using JFileChooser.
    help me,
    thanx in advance

    JFileChooser lets you choose a file. Once it's done you will have to program the copy function with womething like :
         public void copyToDir(String fileSource,String fileDest) {
              try {
                   FileChannel srcChannel = new FileInputStream(fileSource).getChannel();
                   FileChannel dstChannel = new FileOutputStream(fileDest).getChannel();
                   dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                   srcChannel.close();
                   dstChannel.force(true);
                   dstChannel.close();
              } catch (IOException e) {
                   e.printStackTrace();
         }

Maybe you are looking for