Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2009
    Posts
    14
    Rep Power
    0

    Default need to copy file from one location to another location

    Hi Everyone,

    I want to copy the jpeg file from one location to another location means locally from one drive to another drive can anyone guide me how to do this using java......

    Thanks a lot in advance.......

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by naveen.dpt2007 View Post
    Hi Everyone,

    I want to copy the jpeg file from one location to another location means locally from one drive to another drive can anyone guide me how to do this using java......

    Thanks a lot in advance.......
    Open a FileOutputStream for the new file; open a FileInputStream for the old file. Read from the input stream and write to the output stream until you're done. Close both streams afterwards. Don't use Readers and Writers because they are for characters and a jpeg file certainly isn't made up of characters.

    kind regards,

    Jos

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    ... but do wrap your file streams in buffered streams since I think that this should improve throughput (right?).

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    ... but do wrap your file streams in buffered streams since I think that this should improve throughput (right?).
    Yep, but filing systems themselves use buffered streams too; typically files are 'read ahead' for 4KB or 8KB; double buffering doesn't help much there: the data is simply copied from one buffer to the other one. The 'best' solution would be to use mapped ByteBuffers and let the MMU (Memory Management Unit) do the hard work.

    kind regards,

    Jos

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JosAH View Post
    Yep, but filing systems themselves use buffered streams too; typically files are 'read ahead' for 4KB or 8KB; double buffering doesn't help much there: the data is simply copied from one buffer to the other one. The 'best' solution would be to use mapped ByteBuffers and let the MMU (Memory Management Unit) do the hard work.

    kind regards,

    Jos
    Ah, OK. Thanks for clearing that up!

Similar Threads

  1. Getting to original File location
    By ravjot28 in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 04:00 PM
  2. how to specify location of file to be uploaded?
    By anthrax in forum New To Java
    Replies: 11
    Last Post: 01-13-2010, 02:48 PM
  3. location provider returns no location
    By sandeeprao.techno in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-24-2009, 09:54 AM
  4. File Location
    By bcbird in forum New To Java
    Replies: 1
    Last Post: 09-17-2009, 08:03 AM
  5. Transferring a .txt file from 1 location to another
    By dbashby in forum New To Java
    Replies: 2
    Last Post: 04-15-2009, 05:22 AM

Posting Permissions

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