Reputation: 404
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
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