Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

copy command and renaming

 
praveen livingstone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
praveen livingstone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try Ulf's example with a GIF file?
 
praveen livingstone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic