String Tokenizer

what i want to do is to transfer  contents of file
which is in the formate
also i have to do some validations on individual tokens
like if toiken is ip address as shown
then get name of server append it to buffer
that's ok

so what i am doing is using a stream tokenizer
but the problem is when
i say
      name = tokenizer.nextToken()
      //validations like this
what happens is for the first line  there is no ip address
hense while loop can't get terminated it gives exception
as no such element exists
what i need is that  loop shuld be terminated if there r no tokens
can any one help me
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Since the format of each line is variable, you need to model this as a state machine, e.g.

int state = 1;
while (tokenizer.hasMoreTokens())
      case 1:
         // we are expecting an "aaa"
         // type token.
         // if we get it, process it
         // and set state to 2...
         // if we don't get it,
         // set state equal to
         // something else...
      case 2:
         // etc.
      // etc

When doing something like this, you need to map out your process using a state diagram. (BTW, there are better/cleaner ways to build a state machine, but the above is clear and easy to understand...)
amitdAuthor Commented:
this doesn'twork
seems that
the problem lies with the .nextToken()
so why don't u retrieve tokens in the
  Vector V = token.NextToken()

then use it for validations

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amitdAuthor Commented:
thanx it works
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.