File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IO Doubt

 
Abhi vijay
Ranch Hand
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Whys is line2 returning false. In this case file2 has not even been created.
 
Punit Singh
Ranch Hand
Posts: 952
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Ruben Soto
Ranch Hand
Posts: 1032
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhi vijay
Ranch Hand
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 952
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
....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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic