3) Please dnt concisder for what exception it throws.
The Problem is even if file f1 is there it not deleted and f2 is not renamed to f1
And why is the exception not important? For all we know, you could have a null pointer exception on the first line of the try block -- and the none of the delete or rename code is even executed.
will please explain clearly and if possible suggest me ......
redards
DAM
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18641
posted
0
Um, Henry seems to be assuming that an exception is thrown. If that's the case, then absolutely, report its error message and stack trace. However the methods delete() and renameTo() were written by perverse programmers who didn't feel the need to throw any exception in case of failure - they just return false. I consider it an embarrassment that Java has not provided better methods than these, in all this time.
Damodar, there are several possible reasons why these might fail:
Another stream or program may still be open for that file - be sure that streams are closed in a finally block before you try to delete.
One of the paths may be incorrect
You may not have permission to delete or rename that file.
The file may have already been deleted or renamed.
Unfortunately there's not really a good way to know which is the problem, other than checking each possibility carefully.
will please explain clearly and if possible suggest me ......
The stacktrace gives you the exact error -- down to the exact line of code. If you give us the trace output, maybe we can point you to the right place to look...
Henry seems to be assuming that an exception is thrown
Actually, I didn't assume that an exception was thrown. I was just confused that anyone wouldn't even consider it as valueable to examine, if one was thrown -- which was hinted by the exchange.
[EDIT: Hmmmmm... maybe I did initially assumed it... ]
Henry [ June 07, 2008: Message edited by: Henry Wong ]
was annoying to decipher. Besides the obvious that the method doesn't exist due to the wrong case -- it is the substring() method. Once it was fixed, it was still confusing, as I had a different test filename. This only works if your filename was exactly 7 in length. (BTW, I assumed that the purpose of this was to get the drive letter)