Results 1 to 3 of 3

Thread: Scanner problem

  1. #1
    mkay is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default Scanner problem

    i want the Scanner to read data from a file...
    Scanner sc = new Scanner(new File("file"));
    ->this works,
    but now i'm trying to type the file as a parameter in the console, because i don't want to change the code each time i load a different file
    i tried this..
    Quote:
    Scanner sc = new Scanner(new File(System.in));
    but - fail.
    maybe sb can help me please, thy mkay (:

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Why don't you make a Scanner to get filename and then reassign that Scanner to a FileReader with the filename as a paramater

  3. #3
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    Steps:

    // Create scanner > System.in
    // Get filename from user > store into variable
    // Create file reader with variable from above
    Sincerely, Joshua Green
    Please REP if I help :)

Similar Threads

  1. Problem with scanner
    By JavaJ in forum New To Java
    Replies: 6
    Last Post: 03-16-2010, 09:51 PM
  2. Problem with while loop and the scanner method
    By hhh80p in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 12:47 PM
  3. Problem with scanner
    By Kangaroo128 in forum New To Java
    Replies: 11
    Last Post: 09-01-2009, 09:07 AM
  4. Problem with scanner in loop
    By grifan526 in forum New To Java
    Replies: 2
    Last Post: 07-21-2009, 01:06 AM
  5. Scanner input problem
    By slayer_azure in forum New To Java
    Replies: 3
    Last Post: 05-26-2008, 11:49 PM

Posting Permissions

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