FireFox FireFox - 1 year ago 161
Java Question

Java StringTokenizer.nextToken() skips over empty fields

I am using a tab (/t) as delimiter and I know there are some empty fields in my data e.g.:


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?

Answer Source

Thank you at all. Due to the first comment I was able to find a solution: Yes you are right, thank you for your reference:

 Scanner s = new Scanner(new File("data.txt"));
        while (s.hasNextLine()) {
            String line = s.nextLine();
            String[] items= line.split("\t");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download