my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IO Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IO Doubt" Watch "IO Doubt" New topic
Author

IO Doubt

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509


Whys is line2 returning false. In this case file2 has not even been created.
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
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
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
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
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
....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://aspose.com/file-tools
 
subject: IO Doubt
 
Similar Threads
Want to write a combined text file, but nothing happens..
Windows File Paths
renameTo method in io package...
I/O K&B Question
why doesn't this work?