aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes File I/O Operations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "File I/O Operations" Watch "File I/O Operations" New topic
Author

File I/O Operations

Mckenzie John
Greenhorn

Joined: Sep 21, 2012
Posts: 16
Hi

i need to understand the file I/O operations in the following code

package com.scjp;


[Anayonkar]: Added code tags


I have added my questions against the lines as comment. Please help me understanding the concepts.

Thanks,
Mckenzie
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 375
    
    1

That is happening because, when you are renaming your file to a different file object, then a new file is created, content of old file / directory is copied there, and the old file/directory is deleted.

So, after the rename operation, your directory referenced by `file` object doesn't exist.

Try using this: -

Chan Ag
Bartender

Joined: Sep 06, 2012
Posts: 1022
    
  15
Try changing your code as follows.



and



And delete myDir and newDirName ( physical directories and files) and run this program twice and note the difference. That will answer your first and second question.

As for the last question, I think the original file/dir references are not deleted after we rename a file/directory. In any case a File object is just a file ( directory or file ) name that exists even after a rename. The old reference has a name ( file/directory name) but the actual physical dir/file as such does not exist cause it has been renamed. It is the new reference that is now mapped with the physical file/direcory after the rename. So a file or directory reference variable would still have the same name although the actual file/directory may not exist.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File I/O Operations