• 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

Trouble with renaming files using Java 8 on Windows Vista

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Group!

I want to thank you for your help so far. My next issue is that I am deleting a file and renaming it and it is saying cannot rename file. Now all my permissions of the directory and the file has been set to read/write so that isn't an issue. The file gets deleted and the temp file gets created just fine. The renaming is what is not being done. I have read alot in the past day about how renaming is platform dependant and I tried several ways to rename a file with out success. I will post the code for your review and thanks again! - Scott



I do not think I am missing anything as the delete and create file works just fine. Thanks!
 
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This above statement doesn't create a file; its a File object, but not an actual physical file in a directory. The file gets created when you do this:



Then this tempFile can be renamed to the inFile, as you intended to.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand that code, though that could be because it's first thing in the morning.

It looks to me like you copy from a file (data.txt) to a file (datatemp.txt) and then delete the first file (data.txt).
You then try and rename a third file (one called data.txt.tmp) to data.txt, except that third file simply doesn't exist.

Can I suggest that, rather than writing out the file paths twice each (which is prone to error) that you use the File objects you have created when opening the reader/writer?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic