Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Change file extension (Very urgent)  RSS feed

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am running java application. I write the file to local disk. Let's say
in C:/temp i wrote file xyz.data. I want to change the extension to .tif I mean xyz.tif. How can I do that???
Thanks,
Angela
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Angela,
Look at the File class it has a renameTo method.
Regards,
Manfred.
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already tried doesn't work???
Originally posted by Manfred Leonhardt:
Hi Angela,
Look at the File class it has a renameTo method.
Regards,
Manfred.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what happens when it "doesn't work"? Does it throw an exception? Does renameTo() return false? What does your code look like? What are the file permissions on the file you're renaming?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes - if you just recently wrote the file in your program, did you make sure that you closed the FileOutputStream (or whatever you used to write the file)? It's easy to be careless with these - if you forget to close a file, the garbage collector will usually end up closing it for you (eventually), so you often don't notice any problem. But if you try to do something else with the file before GC has had a chance to close it, there are problems. It's best to always make sure you close a stream yourself as soon as you're done with it.
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Jim, but would you please send me an example of this...
Thanks again,
Angela
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Angela,
The listings 11.1 and 11.2 of the Practice Makes Perfect - JavaWorld
explains the traps related to the renameTo() function.

MSM
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it...
Thanks a lot...
Angela
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!