wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes copy command and renaming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "copy command and renaming" Watch "copy command and renaming" New topic
Author

copy command and renaming

praveen livingstone
Greenhorn

Joined: Apr 13, 2008
Posts: 7
In a java program, how can I copy a file from a location and past it in another location? Also how can I rename an existing file?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
Java does not have a command to copy files. You'd need to use a FileInputStream to read the file, and then write it elsewhere using FileOutputStream. Here's an example of how to do that.

As to renaming (and moving) files, that's done with the java.io.File.renameTo method.


Ping & DNS - updated with new look and Ping home screen widget
praveen livingstone
Greenhorn

Joined: Apr 13, 2008
Posts: 7
thanks for the reply but the problem is your method would work for text based copying but i want to copy an image file(GIF) from one location to another. Is there any way that i can do this in JAVA?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8703
    
    6

Did you try Ulf's example with a GIF file?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
praveen livingstone
Greenhorn

Joined: Apr 13, 2008
Posts: 7
@Joe Ess : yea i made mistake, posted without trying the code. now i tried it and its working good. thanks

@Ulf Dittmer : thank you so much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: copy command and renaming
 
Similar Threads
Property File inside the jar
copy files
How to cut a file from one location
Copying a file form one location to another location
File copy and paste