Re: StreamTokenizer question
Philippe wrote:
I'm trying to read a file with many entry. Thus, the first colum is a date.
Here's a row example :
08/22/05 15:18:47 21.00 0.00 0.00 -0.113 -1861.3 397.7 169.4 38.8 8.7
When I'm reading the first token (I'm using StreamTokenizer class) the first
token is 08.0. It looks like he consider the first one as a number. I
would like to ead the first token as 08/22/05.
I tryed to use st.ordinaryChar('/'); but it dont hlep me.
So my question is, how I can read the first token as a string instead of 3
oken considered as numerical.
Try look at this code:
package june;
import java.util.StringTokenizer;
public class ST {
public static void main(String[] args) {
String s = "08/22/05 15:18:47 21.00 0.00 0.00 -0.113 -1861.3
397.7 169.4 38.8 8.7";
StringTokenizer st = new StringTokenizer(s);
while(st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
String[] parts = s.split(" ");
for(int i = 0; i < parts.length; i++) {
System.out.println(parts[i]);
}
}
}
You can easily parse the strings to int or Date if needed.
Arne