Whys is line2 returning false. In this case file2 has not even been created.
Punit Singh
Ranch Hand
Joined: Oct 16, 2008
Posts: 952
posted
0
Abhi vijay wrote:
Whys is line2 returning false. In this case file2 has not even been created.
As there is no such file (file2.txt) in the file system.
Now replace those last two lines with these line.
What did you get?
SCJP 6
Ruben Soto
Ranch Hand
Joined: Dec 16, 2008
Posts: 1032
posted
0
You answered your own question. According to the API, isFile() returns true if and only if the file denoted by this abstract pathname exists and is a normal file. Since in this case the file does not exist, it returns false.
All code in my posts, unless a source is explicitly mentioned, is my own.
Abhi vijay
Ranch Hand
Joined: Sep 16, 2008
Posts: 509
posted
0
But a file is created when file.createNewFile() is invoked
.
Here file2.createNewFile(); is never invoked. Then how is file2 created???
Punit Singh
Ranch Hand
Joined: Oct 16, 2008
Posts: 952
posted
0
Abhi vijay wrote:But a file is created when file.createNewFile() is invoked
.
Here file2.createNewFile(); is never invoked. Then how is file2 created???
Where is the output? Ya file2.txt will not be created, but it could be existing already also na.
Abhi vijay
Ranch Hand
Joined: Sep 16, 2008
Posts: 509
posted
0
....oops... Thanks Punit.
I thought that isFile() only checks whether it is a file/not. But it turned out that it also checks whether that particular file is present in the system/current directory.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.