• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Copying a File to other directory

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have the requirement in which i have to copy dynamically determined files to other directories.I can do it by using the input and output streams but i am dealing with 5GB of data so i dont want the process to slow down.Can some one help me with this.
Thanks,
Hari
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With input and output streams you can read and write big chunks to & from byte arrays. The bigger the chunk, the fewer the IO calls to the OS and fewer the physical reads, and (one would expect) all the faster. It's still going to take time with gigabytes of data, tho. I haven't used NIO at all - there might be some non-blocking streams that would let you read and write at the same time on threads managed by NIO.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can use JDK 1.4, then java.nio.channels.FileChannel has transferTo() and transferFrom() methods that should be much faster, especially for large volumes of data. Otherwise, gotta use streams. And as Stan says, read a few big chunks, rather than lots of little chunks. Something like:

Also note that if you ever need to move a file rather than copy it, File has a renameTo() method that is probalbly what you want here.
[ December 02, 2003: Message edited by: Jim Yingst ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic