try this
StringTokenizer Token1 = new StringTokenizer(file2.trim(), " ");
...
Question
StringTokenizer Token1 = new StringTokenizer(file2," ");
while(Token1.hasMoreTokens()) {
String word = Token1.nextToken();
if(word.equals(Query1)){
x =1;
System.out.println("help");
}else if(word.equals(Query2)){
y =1;
}
This is my code, it splits the string fine but the last token always has a \n and when I try to compare the last token with a value it should be it fails.
Thank you .trim() work perfectly :) :)
Solution
try this
StringTokenizer Token1 = new StringTokenizer(file2.trim(), " ");
...
OTHER TIPS
StringTokenizer Token1 = new StringTokenizer(file2.replace("\n", ""), " ");