Hi,
I am reading lines from a txt file and splitting words using StringTokenizer. My code is as below:
File:
BufferedReader in = new BufferedReader(new FileReader(FILENAME));
String line = in.readLine();
while(line != null) {
StringTokenizer tk = new StringTokenizer(line);
String first = tk.nextToken(),
second = tk.nextToken(),
third = tk.nextToken(),
fourth = tk.nextToken();
------
------
line = in.readLine();
}
In Line 1, there are 4 words - aaa, bbb, ccc, ddd which gets assigned to variables first, second, third and fourth.
In Line 2, there are only 3 words, The
word that should be assigned to variable third is missing.
I want that the variable 'third' should not be assigned anything in the Line 2. But StringTokenizer treats all the spaces as delimiters.
How can this be done?
Thanks,
Nidhi
[ EJFH: Added "CODE" tags to preserve formatting in data file. ]
[ August 27, 2007: Message edited by: Ernest Friedman-Hill ]