Rohit Haritash
Rohit Haritash

Reputation: 404

StringTokenizer only taking last word of the line

HI i am trying to tokenise a text file using StringTokeniser in java. But the problem is it only takes the last word of the line. Little help is needed. This sample code is part of a map-reduce function.

String profile;

StringTokenizer inputKey=new StringTokenizer(value.toString());
while(inputKey.hasMoreTokens()){

    String input=inputKey.nextToken();
    if(!input.endsWith("</id>")){
        textInput.set(input);
    } else {
        profile=input.substring(4,15);
        profileId.set(profile);

    }
}

Upvotes: 0

Views: 1415

Answers (2)

HJW
HJW

Reputation: 23443

You should use a debugger as most have said, and stop using StringTokenizer and starting String.split..

You have instantiated a StringTokenizer object without the delimiter, you can either set the delimiter explicitly (it could be "," or "." In your case) or use a constructor that accepts both the delimiter and the String that you are trying to parse.

Upvotes: 2

boskop
boskop

Reputation: 619

These kind of problems are perfect to learn how to debug a program.

Upvotes: 0

Related Questions