Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Scanner help

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    38
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Scanner help

    I need a scanner to go through a file an see if it contains a certain string. Is there a method that I can use or am I out of luck? I essentially need a contains method but for the scanner and after looking through the java docs I can't seem to find one. any ideas?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Scanner help

    Read the lines of the file into a List, and then check whether the List contains the String. Or just check each line as it's read in.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    sp11k3t3ht3rd (June 22nd, 2011)

  4. #3
    Member
    Join Date
    Oct 2010
    Posts
    38
    Thanks
    11
    Thanked 1 Time in 1 Post

    Default Re: Scanner help

    Thanks! I added a while loop for while the file has another line. Then in that is an if statement where if the string is the next string in the file, it does what it's supposed to. Otherwise it goes to the next line. If there isn't another line then it tells you that the item doesn't exist. Thanks a ton

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Scanner help

    Sounds really reasonable to me. Glad you got it sorted out.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. scanner reading
    By awan in forum Java SE APIs
    Replies: 2
    Last Post: June 18th, 2011, 11:39 AM
  2. Console box with scanner?
    By Hallowed in forum Java Theory & Questions
    Replies: 1
    Last Post: May 26th, 2011, 12:50 AM
  3. Scanner/FileReader help
    By JohnTravoltaire in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 28th, 2011, 12:28 AM
  4. Scanner problem - need help
    By destructobob in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 23rd, 2011, 02:08 AM
  5. Help With Scanner
    By jtphenom in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 12th, 2009, 08:49 PM