aspose file tools*
The moose likes Beginning Java and the fly likes StringTokenizer errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringTokenizer errors" Watch "StringTokenizer errors" New topic
Author

StringTokenizer errors

Pip Vo
Greenhorn

Joined: Jul 18, 2001
Posts: 12
Dear Ranchers:
I need to parse strings (but don't
care if they're letters or #s). I was using
StreamTokenizer b4, but a post suggested
StringTokenizer so switched to that and still
get errors. Please advise on the code below. Thanx
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.io.*;
import java.util.StringTokenizer;
public class tokenizer2
{
public static void get_data1()
{
try
{
FileReader filereader = new FileReader("file.txt");
StringTokenizer st = new StringTokenizer(filereader);

System.out.println("Following parameters will be used in RECTANGLE object:");
while (st.hasMoreTokens())
{
println(st.nextToken());
}
filereader.close();
} // end try
catch(IOException e) {System.out.println("ERROR!");}
} // end get_data1()

public static void main(String s[])
{
get_data1();
}
}
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, what does the error message say? Those are invaluable in trying to diagnose what the problem is. Also, be sure to consult the API for the classes and methods you use - particularly the ones that appear in the line(s) which throw an error.


"I'm not back." - Bill Harding, Twister
Pip Vo
Greenhorn

Joined: Jul 18, 2001
Posts: 12
Thanks for the reply. My error messages:
tokenizer2.java:21: cannot resolve symbol
symbol : constructor StringTokenizer (java.io.FileReader)
location: class java.util.StringTokenizer
StringTokenizer st = new StringTokenizer(filereader);
This code came from Sun's API webpage ... so am
surprised it's not working.
tormod eriksen
Ranch Hand

Joined: Jan 23, 2002
Posts: 52
You can't pass a FileReader to the StringTokenizer constructor (at least not under j2se 1.3).
Here's an overview of the constructors:
StringTokenizer(String str)
StringTokenizer(String str, String delim)
StringTokenizer(String str, String delim, boolean returnDelims)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringTokenizer errors