I am using a tab (/t) as delimiter and I know there are some empty fields in my data e.g.:
one->two->->three
Where -> equals the tab. As you can see an empty field is still correctly surrounded by tabs. Data is collected using a loop :
while ((strLine = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(strLine, "\t");
String test = st.nextToken();
...
}
Yet Java ignores this "empty string" and skips the field.
Is there a way to circumvent this behaviour and force java to read in empty fields anyway?
There is a RFE in the Sun's bug database about this StringTokenizer
issue with a status Will not fix
.
The evaluation of this RFE states, I quote:
With the addition of the
java.util.regex
package in1.4.0
, we have basically obsoleted the need forStringTokenizer
. We won't remove the class for compatibility reasons. Butregex
gives you simply what you need.
And then suggests using String#split(String)
method.