• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File renameto doesn't change the name of the file

 
Fabio Landoni
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a little problem with the file name.

This is my code:

After the renameTo I check thath "hasBeenRenamed" is true and i hask for a syste.out.println(oldFile.getName()) it gives me the old name of the file, but in the filesystem the file has been renamed!

Some one can help me?
thanks
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's how File works.

From the javadoc for File
Instances of the File class are immutable; that is, once created, the abstract pathname represented by a File object will never change.

 
Fabio Landoni
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:That's how File works.

From the javadoc for File
Instances of the File class are immutable; that is, once created, the abstract pathname represented by a File object will never change.



Ok thank you
 
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
Remember, a java.io.File doesn't represent a "file", really; it represents a path to a file. When you call methods like renameTo() or size(), they look onto the file system at the corresponding path, and they won't work unless the file exists. But you can create a java.io.File to represent completely nonexistent paths, and that's perfectly OK.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic