Results 1 to 3 of 3
  1. #1
    bayan is offline Member
    Join Date
    Apr 2010
    Posts
    55
    Rep Power
    0

    Exclamation Copying large files efficiently

    Is there any way to use the copy function of the operating system to copy and paste large files because I cannot think of any efficient algorithms for copying 125mb avi files. With the algorithm I have it takes around 5 minutes to copy one 125 MB file.

    If I can't use the operating system default function, can anyone tell me how to speed up the process, because buffer size seems to have no effect on the speed

    Here is the algorithm I'm using:

    Java Code:
    // Copy the file infile as another file in a different directory outfile
        private static void copy(File infile, File outfile){
            
            
        try{
    
            //Open a stream of bytes to read the file bytes into the program
            FileInputStream instream = new FileInputStream(infile);
            //A stream of bytes from the program to the destination
            FileOutputStream outstream = new FileOutputStream(outfile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            //Write the bytes from the inputstream to the outputstream
            while((bytesRead = instream.read(buffer))!=-1){
    
                outstream.write(buffer, 0, bytesRead);
                
            }
    
            // Finally close both streams to save garbage disposal memory
            instream.close();
            outstream.close();
            }catch(FileNotFoundException e){e.printStackTrace();
            
            }
             catch(IOException e){e.printStackTrace();}
            
            }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Try FileChannel and its "copy" method.

  3. #3
    bayan is offline Member
    Join Date
    Apr 2010
    Posts
    55
    Rep Power
    0

    Default

    Thanks it reduced the copy time from 5 mins 8 seconds to 13 seconds. Thanks a lot :D

    For others with the same problem here is the algorithm:

    Copying File Contents using FileChannel

Similar Threads

  1. Copying Files
    By tgns223 in forum New To Java
    Replies: 13
    Last Post: 06-12-2010, 03:15 AM
  2. How can I do this more efficiently ?
    By chucklesotoole in forum New To Java
    Replies: 5
    Last Post: 06-04-2010, 02:28 PM
  3. Compare 2 large files
    By bezudar in forum Advanced Java
    Replies: 3
    Last Post: 11-23-2008, 02:18 AM
  4. OutofMemory while downloading large files through FTP
    By deb_santanu in forum Advanced Java
    Replies: 0
    Last Post: 11-13-2008, 01:04 PM
  5. Need to find large files and folder on the PC. What app needed?
    By Cleaner007 in forum Reviews / Advertising
    Replies: 1
    Last Post: 09-30-2008, 07:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •