I need to do some plain file copying and moving from Java code. If I was
doing it in Linux, I'd be doing "mv file1 dir1" or "cp file2 dir2", that
sort of thing.
How do I do this in Java without using a system call to mv or cp ? And I
don't want to open the file, make a new file and copy the contents from
one to another, at least if I don't have to.
Thanks.
ge0rge - 05 Nov 2006 18:38 GMT
> I need to do some plain file copying and moving from Java code. If I was
> doing it in Linux, I'd be doing "mv file1 dir1" or "cp file2 dir2", that
[quoted text clipped - 3 lines]
> don't want to open the file, make a new file and copy the contents from
> one to another, at least if I don't have to.
Go and read the Java Tutorial on file IO
http://java.sun.com/docs/books/tutorial/essential/io/file.html
Do a search on java file copy on Google.
You will definitely find what you are looking for.

Signature
In the strict scientific sense we all feed on death -- even vegetarians.
-- Spock, "Wolf in the Fold", stardate 3615.4
Shanmuhanathan T - 06 Nov 2006 11:56 GMT
me2 said,on 05/11/2006 11:30 PM:
> I need to do some plain file copying and moving from Java code. If I was
> doing it in Linux, I'd be doing "mv file1 dir1" or "cp file2 dir2", that
[quoted text clipped - 5 lines]
>
> Thanks.
try the java NIO libarary - it provides a faster mechanism for file I/O.
one good tutorial is at
www.ibm.com/developerworks/java/edu/j-dw-java-nio-i.html
(registration required....blah blah)
Regards,
Shanmu.

Signature
When told he was making more per year than the President,
Babe Ruth replied, "Well, I had a better year than he did."
me2 - 08 Nov 2006 00:09 GMT
> me2 said,on 05/11/2006 11:30 PM:
>> I need to do some plain file copying and moving from Java code. If I was
[quoted text clipped - 15 lines]
> Regards,
> Shanmu.
So there is no File.copy() or anything like that ? I need to move and copy
files from one directory to another.
Tor Iver Wilhelmsen - 08 Nov 2006 08:04 GMT
> So there is no File.copy() or anything like that ? I need to move and copy
> files from one directory to another.
Copying files means reading from one and writing to another. Remember
to read and write from/to arrays and not single bytes.
Ingo R. Homann - 08 Nov 2006 12:00 GMT
Hi,
> Copying files means reading from one and writing to another. Remember
> to read and write from/to arrays and not single bytes.
Note that for a remote directory (e.g. Samba), it would be very useful
if there was a "native" Copy-Method that does not need to transfer the
file over the network to the 'local' computer and than back to the
remote computer.
Ciao,
Ingo