Results 1 to 2 of 2

Thread: skipping input

  1. #1
    windie_86 is offline Member
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0

    Default skipping input

    Hi, every1. I am new to java and i need to read in a text file.
    This is my text file.

    Name = Jack
    Address = 123 Ripley, Singapore 7666322

    I need to read in the "Jack" and the address without reading in the "Name =" and the "Address =" using Scanner.

    This is my method:
    try
    {
    Scanner input = new Scanner(new File(fileName));
    while(input.hasNext())
    {
    input.next(); input.next();
    String name = input.nextLine().toUpperCase();
    input.next(); input.next();
    String address = input.nextLine();
    new Customer(name, address);
    numOfCustomers++;
    }
    System.out.println(numOfCustomers+" records read.");
    }

    can anybody suggest a better way of doing it if there is more than 2 variables?
    Thank you.

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Welcome to the Java Forums windie

    Your logic should simply be to the tune of:
    i) read in the line
    a) read up to equals sign, disregard
    b) read past equals sign, true
    You can incorporate that logic into your code with a multitude of API methods available to you.

    See you around!
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

Similar Threads

  1. How to get input from Console
    By karma in forum New To Java
    Replies: 8
    Last Post: 08-13-2010, 10:32 PM
  2. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 AM
  3. input placed in array
    By smilejava in forum New To Java
    Replies: 5
    Last Post: 11-12-2007, 08:29 AM
  4. input placed in array
    By smilejava in forum New To Java
    Replies: 1
    Last Post: 11-05-2007, 01:32 PM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 09:46 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
  •