Using a string tokenizer and string buffer to decode a message?
So I have this file in which has a few sentences on a single line. What I need to be able to do is read the file and then take each word and create a token out of it. Then what it does is it selects the first letter of every 5th word, uppercase it, and then allow me to use append it via a stringbuffer object to create a word out of it.
I know I'll need to use a string tokenizer but I'm not sure how to do so in a way that makes each word separate and how to tell it to only hit the 1st letter of every 5th word.
Heres what I've come up with so far, but I'm currently at a loss at what to do and my textbook/documentation is just not helping.
String line; // The line we read from the file.
char letter; // The first letter of each 5th word.
String sw; // The completed string.
public static void main (String  args)throws IOException
FileReader file = new FileReader("secret.txt");
BufferedReader input = new BufferedReader(file);
line = inputFile.readLine();
StringTokenizer st = new StringTokenizer(line);
letter = line.charAt(0);
StringBuilder str = new Stringbuilder(letter);
sw = str.append(letter);
Re: Using a string tokenizer and string buffer to decode a message?
After you read in a line and pass it to the StringTokenizer constructor,yYou need to call a StringTokenizer method to get the next token from that line into a String. See the API doc for a short example.