Results 1 to 5 of 5

Thread: hasNext call

  1. #1
    scotts is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default hasNext call

    Hi,
    trying to create a program that reads off usernames from the email add..
    this is the code:
    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintStream;
    class TestinOne
    {
    public static void main(String args[])
    throws FileNotFoundException
    {
    Scanner diskScanner = new Scanner(new File("email1.txt"));
    PrintStream diskWriter = new PrintStream ("usernamesright.txt");
    char symbol;
    while(diskScanner.hasNext())
    {
    symbol = diskScanner.findInLine(".").charAt(0);
    while ( symbol != '@')
    {
    diskWriter.print(symbol);
    symbol = diskScanner.findInLine(".").charAt(0);
    }
    }
    diskScanner.nextLine();
    diskWriter.println();
    }
    }
    but its not working..
    any solutions?
    thkx

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default

    but its not working
    Can you show what it does do, why that is wrong and what you want changed?

    Does "diskScanner.findInLine(".")" always return a String? Read the doc.
    Maybe you should test what is returned first.
    Last edited by Norm; 06-20-2010 at 01:53 PM.

  3. #3
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    And also "it's not working" doesn't help us help you. Please see: It Doesnt Work Is Useless

  4. #4
    scotts is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    Hi,
    sry abt the lack of details..
    instead of getting the usernames only, whatever comes before and after the @ is printed in the usernamesright.txt file. ie instead of printing joho from the email address joho@hotmail.com, it prints johohotmail.com..
    plus it does not go till the end of the file..ie the second email add username is not being printed..
    any solutions..
    thks

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default

    For debugging add println()s to show the values of the variables as they are read in and as they are changed.
    For example what value is returned by: diskScanner.findInLine(".")?

Similar Threads

  1. call a JSP method
    By sauravsinha in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 09-26-2011, 05:19 PM
  2. gwt rpc asynchronous call
    By trust in forum Web Frameworks
    Replies: 1
    Last Post: 08-11-2009, 11:42 AM
  3. not able to call the ejb
    By deepak9976 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 08-07-2009, 11:12 AM
  4. how to call method?
    By leapinlizard in forum New To Java
    Replies: 9
    Last Post: 04-30-2009, 12:55 AM
  5. Using scanner.hasNext() but recognize return
    By ScKaSx in forum New To Java
    Replies: 5
    Last Post: 01-27-2009, 11:11 AM

Posting Permissions

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