aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding --> fileObj.renameTo(newFileObj) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding --> fileObj.renameTo(newFileObj)" Watch "Regarding --> fileObj.renameTo(newFileObj)" New topic
Author

Regarding --> fileObj.renameTo(newFileObj)

Sathi Krishna
Ranch Hand

Joined: Oct 21, 2007
Posts: 51

Hi,
When I Run the below sample code, I am getting exception at runtime




The output I am getting is

Before Rename : E:\Development\DoNBeTheBest\MyDir\MyFile.txt
After Rename : E:\Development\DoNBeTheBest\MyDir\MyFile.txt
java.io.FileNotFoundException: MyDir\MyFile.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at java.io.FileWriter.<init>(FileWriter.java:73)
at svkr.kb.ch06.ListFiles.main(ListFiles.java:28)

Why after renaming also txtFile object pointing the old directory?

Thank You



Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Sathi Krishna wrote:Why after renaming also txtFile object pointing the old directory?

Because the documentation says so

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


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding --> fileObj.renameTo(newFileObj)