• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

renaming a file with a filename that already exists

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I was wondering, how do you rename a file? And if there already is a file named that...how do you overwrite it and replace the file thats already there with the new file with the same name?

Sorry, I'm not sure whether this belongs to beginner or intermediate, please don't fine me!
[ June 15, 2005: Message edited by: jin sun ]
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you may wish to check the API documentation for the "File" class; there's a method in there that can rename files.

whether or not it can rename files to a name which already exists isn't specified in those docs, unfortunately. the quick and easy way to find out would be to try it and see what happens, i suppose. but that's assuming that this behaviour isn't platform-dependent; it shouldn't be, but i can't be entirely certain.

even if it is platform-dependent, though, there is likely an easy work-around that will work everywhere. after all, if you're trying to rename a file "A" to be named "B", but another file named "B" already exists, what do you want to happen to the "B" that already exists? there are probably methods in the "File" class that can do that for you.
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic