| Author |
File I/O Operations
|
Mckenzie John
Greenhorn
Joined: Sep 21, 2012
Posts: 14
|
|
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: 276
|
|
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: -
|
OCPJP
|
 |
Chan Ag
Ranch Hand
Joined: Sep 06, 2012
Posts: 39
|
|
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.
|
 |
 |
|
|
subject: File I/O Operations
|
|
|