File util API to move files accross partitions/filesystems

D

dwi2004

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
 
R

Roedy Green

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
 
G

Gordon Beaton

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
 
R

Roedy Green

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.
 
G

Gordon Beaton

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
 
G

Gordon Beaton

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
 
C

Chris Uppal

Gordon said:
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
 
D

dwi

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
 
B

Benji

dwi said:
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)
 
L

Luc The Perverse

Benji said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top