File util API to move files accross partitions/filesystems

Discussion in 'Java' started by dwi2004@gmail.com, Nov 15, 2005.

  1. Guest

    Hi,
    I'm looking for an open source java file utility/API that has a
    method to
    move files accross filesystems. Can anybody suggest one ?

    BTW, I recently discover a class in Ant API called
    org.apache.tools.ant.taskdefs.Move, extending Copy class. Is this a
    good alternative to do the above task ?

    I'm currently using jsdk 1.4, where the java.io.File.renameTo() method
    is platform dependent, ie. this method does not work when multiple
    partitions/filesystem
    are involved.

    Thanks a lot !!

    Dwi
     
    , Nov 15, 2005
    #1
    1. Advertising

  2. Guest

    You can use the free open-source Apache Jakarta Commons IO library.
    http://jakarta.apache.org/commons/io/
    In it you will find the org.apache.commons.io.FileUtils class that
    might help you.

    Regards
     
    , Nov 16, 2005
    #2
    1. Advertising

  3. Roedy Green Guest

    On 15 Nov 2005 12:47:56 -0800, wrote, quoted or
    indirectly quoted someone who said :

    > I'm looking for an open source java file utility/API that has a
    >method to
    >move files accross filesystems. Can anybody suggest one ?


    The OSes don't let you do that for security reasons. You don't want
    folk out on the net fiddling with your files as if there were their
    own.

    So you need to write a pair of programs that communicate. The server
    on one gets requests from the other and writes the data it receives.
    It does some sort of check to make sure the incoming traffic is legit,
    and only writes files in certain places to make sure malicious people
    can't trash valuable files.

    In practice you might consider the following tools for copying files
    between filesystems

    http://mindprod.com/jgloss/ftp.html
    http://mindprod.com/jgloss/rsync.html
    http://mindprod.com/webstarts/replicator.html
    http://mindprod.com/products1.html#FILETRANSFER
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 16, 2005
    #3
  4. On Wed, 16 Nov 2005 10:17:55 GMT, Roedy Green wrote:
    > So you need to write a pair of programs that communicate. The server
    > on one gets requests from the other and writes the data it receives.


    I beleive you've misunderstood the request: "across filesystems" means
    across partitions or physical disks within the same system. Renaming
    isn't sufficient, you need to read from the source file, write to the
    destination file, and ultimately remove the source file.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Nov 16, 2005
    #4
  5. Roedy Green Guest

    On 16 Nov 2005 13:01:26 +0200, Gordon Beaton <> wrote,
    quoted or indirectly quoted someone who said :

    >I beleive you've misunderstood the request: "across filesystems" means
    >across partitions or physical disks within the same system. Renaming
    >isn't sufficient, you need to read from the source file, write to the
    >destination file, and ultimately remove the source file.


    In that case, you can do it with a script copy or with the
    FileTransfer class.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 16, 2005
    #5
  6. On Wed, 16 Nov 2005 12:45:28 GMT, Roedy Green wrote:
    > In that case, you can do it with a script copy or with the
    > FileTransfer class.


    *The* FileTransfer class?

    AFAIK there is no such class included as part of any Sun JDK. A Google
    search results in at least a handful of classes with that name.

    Anyway to the OP: copying a file from one partition to another
    requires not more than about 10 lines of code (read from an
    InputStream, write to an OutputStream, repeat until EOF, close both).

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Nov 16, 2005
    #6
  7. On Wed, 16 Nov 2005 14:08:47 -0000, Chris Uppal wrote:
    > Unless you also want to preserve permissions, access times, etc. (Which may
    > not be the case for the OP.)


    (hmm, didn't think of that)

    AFAIK you can't preserve those (or change them after the copy) from within
    Java.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Nov 16, 2005
    #7
  8. Chris Uppal Guest

    Gordon Beaton wrote:

    > Anyway to the OP: copying a file from one partition to another
    > requires not more than about 10 lines of code (read from an
    > InputStream, write to an OutputStream, repeat until EOF, close both).


    Unless you also want to preserve permissions, access times, etc. (Which may
    not be the case for the OP.)

    -- chris
     
    Chris Uppal, Nov 16, 2005
    #8
  9. Roedy Green Guest

    On 16 Nov 2005 14:57:27 +0200, Gordon Beaton <> wrote,
    quoted or indirectly quoted someone who said :

    >*The* FileTransfer class?


    the one I mentioned in my previous post
    http://mindprod.com/products1.html#FILETRANSFER
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 16, 2005
    #9
  10. dwi Guest

    Thanks for all the replies so far. I may decide then to write my own
    instead.
    I looked at CommonsIO, and I can not find any one.

    My requirement is actually simpler, ie. within the same server, but
    with multiple partitions.

    BTW, Anyone can advise on the performance point of view? I heard that
    copying file using
    the usual InputStream read() and write() is not really efficient,
    especially with large file.
    Someone suggests using FileChannel class instead. Any suggestion ?

    Cheers, Dwi
     
    dwi, Nov 18, 2005
    #10
  11. Benji Guest

    dwi, while chewing on bamboo shoots, wrote:
    > BTW, Anyone can advise on the performance point of view? I heard that
    > copying file using
    > the usual InputStream read() and write() is not really efficient,
    > especially with large file.
    > Someone suggests using FileChannel class instead. Any suggestion ?


    yes. use a FileChannel. ;-) (it is much more efficient)

    --
    Of making better designs there is no end,
    and much refactoring wearies the body.
     
    Benji, Nov 18, 2005
    #11
  12. "Benji" <> wrote in message
    news:dlll69$m00$...
    > dwi, while chewing on bamboo shoots, wrote:
    >> BTW, Anyone can advise on the performance point of view? I heard that
    >> copying file using
    >> the usual InputStream read() and write() is not really efficient,
    >> especially with large file.
    >> Someone suggests using FileChannel class instead. Any suggestion ?

    >
    > yes. use a FileChannel. ;-) (it is much more efficient)


    Is that true when doing nothing but reading/streaming a file?

    I will take any performance advanced when getting hashes of files on my
    drive.

    --
    LTP

    :)
     
    Luc The Perverse, Nov 19, 2005
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Sobol
    Replies:
    1
    Views:
    417
    Dale King
    Jun 2, 2005
  2. Replies:
    7
    Views:
    1,229
    Roedy Green
    Sep 5, 2005
  3. David McNab
    Replies:
    22
    Views:
    684
    Bengt Richter
    Dec 12, 2003
  4. Replies:
    3
    Views:
    355
    perchef
    Aug 16, 2005
  5. Mitko Haralanov

    Getting mount stats for filesystems

    Mitko Haralanov, Jun 5, 2007, in forum: Python
    Replies:
    7
    Views:
    270
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Jun 5, 2007
Loading...

Share This Page