Name: tb29552 Date: 09/15/97
java.io.StreamTokenizer can't read valid floating point
numbers such as:
-6.77e-005
Strings of this type can be read are valid in
Java. Double.valueOf("-6.77e-005") give the
value I expect when it is printed out. StreamTokenizer
doesn't handle this.
The following java program illustrates this problem:
-------
import java.io.*;
public class test2 {
public static void main(String argv[]) {
try {
Reader r = new BufferedReader(new FileReader("data"));
StreamTokenizer st = new StreamTokenizer(r);
st.parseNumbers();
st.nextToken();
while (st.ttype != StreamTokenizer.TT_EOF) {
if (st.ttype == StreamTokenizer.TT_NUMBER)
System.out.println(st.nval);
else if (st.ttype == StreamTokenizer.TT_WORD) {
System.out.println("error! got word!");
System.out.println("saw "+st.sval+" on line "+st
.lineno());
} else
System.out.println("error!");
st.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
}
-------
The following data file can be used with the program
above:
-------cut here - only include the numbers not this line
1
2.2
3.33
0.44
-6.77e-005
-------cut here - only include the numbers not this line
company - National Center for Supercomputing Applications , email - ###@###.###
======================================================================
Name: skT45625 Date: 03/08/2000
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
StreamTokenizer currently extracts numbers expressed in scientific notation as a
number plus a word. For example, the string "1.23E4" is parsed as number 1.23
and word "E4". This request is to add a method (sample name
StreamTokenizer.parseFloats( boolean flag)), that would allow the user to
specify the behavior of StreamTokenizer (similar to the slashStartComments() and
slashSlashComments() methods). When flag = true, 1.23E4 would be extracted as a
single number, when flag = false 1.23E4 would be extracted as a number plus a
word, as is current. To maintain compatibility with current releases this
setting should default to false.
(Review ID: 102224)
======================================================================