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 / First Aid / November 2006

Tip: Looking for answers? Try searching our database.

copying and moving files in Java ?

Thread view: 
me2 - 05 Nov 2006 18:00 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
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


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



©2008 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.