• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scanner

 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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));
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic