4 Attachment(s)
create(java.io.InputStream) in Scanner cannot be applied to (java.io.File)
Ahhh!!!
Ahem, when I try to compile the attached file, "PhoneDirectory.java", I get the following compilation error message:
Code:
PhoneDirectory.java:12: create(java.io.InputStream) in Scanner cannot be applied to (java.io.File)
Scanner fin = Scanner.create(file);
After quite a bit of tweaking... I'm right back where I started. I'm a seasoned programmer, as far as concepts are concerned, but rather new to JAVA.
The error seems to be occuring where a new instance of "Scanner" is supposed to be created. It uses file I/O, and I have only used the Scanner class for the keyboard input in the past.
Looking at the Scanner class, everything seems to be right to me. I'm probably missing some simple fundamental concept, and I've been pulling my hair out trying to get it... Please help me shed some light on this situation!
Re: create(java.io.InputStream) in Scanner cannot be applied to (java.io.File)
You're missing the concept of type safety :)
file in your code is a java.io.File instance. Scanner.create only accepts a java.io.InputStream reference.
The solution, of course, is to open the file and create an InputStream that you can pass:
Scanner.create(new java.io.FileInputStream(file));