• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

renameTo()?

 
Pete Dawson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to write a simple GUI file renamer using Netbeans 6.8 on Windows. I am having problems getting the renameTo() method to work.

Can anyone see what I am doing wrong?


It did actually work when I ran it using java -jar from the dist directory in a DOS command window and the file was in the same directory. I'm wondering if it is a permissions problem.

thanks

Pete
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you use the fullpath of the file, instead of just the filename ?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This line:

File tempFile = new File(file.getName());

discards all the information about the file's path, keeping only the name. Java will therefore be looking for a file by that name in the current directory. If that's where the file is, then the code will work, but if it's anywhere else, it won't. Just don't do this "tempFile" thing -- use the File object you get from the chooser directly.
 
Pete Dawson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that did it. I can see why now.

Pete
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic