This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Scanner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Scanner" Watch "Scanner" New topic
Author

Scanner

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Source-Whizlabs.

It is given that the file(a.txt) is already exist. Why we need new File(a.txt) in constructor parameter. Can anyone please explain?

Scanner sc=new Scanner (new File(a.txt));


SCJP-1.5<br />SCWCD-1.4
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42367
    
  64
Because "new File(...)" does not create a file - it creates a File object. You need a File object to work with existing files as well as new files.


Ping & DNS - my free Android networking tools app
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Thanks Ulf.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scanner