This is Akshatha. I\'m stuck in parsing the following data. I want to fetch each word individually. Can I have a sample code so that I can proceed
RTRV-HDR RH
I would try String.split(). Something like this...
String [] words;
words = line.split("\s+");
The above splits the string on whitespace.
Use BufferedReader
to read your file (or input stream) thusly.
Then use StringTokenizer
to split each line into tokens thisly
I'm not providing a ready-to-use code here because I think you'd learn better by combining the above examples into a working code yourself.
How about using a Stringtokenizer to fetch each word?
import java.util.*;
public class ReverseWords {
public static void main( String args[] ) {
String s = "Go to the main menu. Quick!";
StringTokenizer tokens = new StringTokenizer(s);
StringBuffer ab;
while (tokens.hasMoreTokens()){
ab = new StringBuffer (tokens.nextToken());
// do your processing
}
System.out.println();
}
}