Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

File util API to move files accross partitions/filesystems

Thread view: 
dwi2004@gmail.com - 15 Nov 2005 20:47 GMT
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
jfbriere@gmail.com - 16 Nov 2005 06:26 GMT
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
Roedy Green - 16 Nov 2005 10:17 GMT
>   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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Gordon Beaton - 16 Nov 2005 11:01 GMT
> 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

Signature

[  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

Roedy Green - 16 Nov 2005 12:45 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Gordon Beaton - 16 Nov 2005 12:57 GMT
> 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

Signature

[  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

Chris Uppal - 16 Nov 2005 14:08 GMT
> 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
Gordon Beaton - 16 Nov 2005 13:56 GMT
> 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

Signature

[  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

Roedy Green - 16 Nov 2005 15:35 GMT
>*The* FileTransfer class?

the one I mentioned in my previous post
http://mindprod.com/products1.html#FILETRANSFER
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

dwi - 18 Nov 2005 22:33 GMT
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
Benji - 18 Nov 2005 22:39 GMT
> 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)

Signature

Of making better designs there is no end,
 and much refactoring wearies the body.

Luc The Perverse - 19 Nov 2005 00:37 GMT
>> BTW, Anyone can advise on the performance point of view? I heard that
>> copying file using
[quoted text clipped - 3 lines]
>
> 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

:)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.