File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding --> fileObj.renameTo(newFileObj)

 
Sathi Krishna
Ranch Hand
Posts: 51
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic