Originally posted by Mingwei Jiang:
I read one line from the file that is separated by tab, and no matter I use "\t" or " " (tab in double quotes), it doesn't work. It can only give me one token instead of 12 which is correct.
Can anyone help me?
Thanks
I don't see anything wrong with this code. Are you sure that line has tab characters in it? Also, are there any characters in between the tab characters. If for example, you have something like
[code]
String line = "\t\tsomething"
[code]
Then StringTokenizer will only return a single token. By default it will not return the "null token" between the two tab characters. I believe there is a method to force it to do so, however.
With that said, I agree that
you should use String.split() or regular experessions instead, if you are using a version of
Java that supports these.
Layne