user1708134
user1708134

Reputation: 673

Scanner with just a File VS Scanner with FileReader and File

Guys i'm just wandering what is the difference between these lines

  1. Scanner file = new Scanner(new FileReader(new File(filePath)));
  2. Scanner file = new Scanner(new File(filePath));
  3. Scanner file = new Scanner(new FileReader(filePath));

is their any kind of instance when you will use them? or their all the same?

Upvotes: 1

Views: 629

Answers (1)

Pace
Pace

Reputation: 43867

They're all identical. The File constructors are for convenience. Sometimes you will get other Readers (not from a File) or need to construct the FileReader yourself (in order to specify an encoding) in which case the Reader constructor is important.

Upvotes: 1

Related Questions