Results 1 to 2 of 2

Thread: create(java.io.InputStream) in Scanner cannot be applied to (java.io.File)

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    1

    Unhappy 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!
    Attached Files Attached Files

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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));
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width