File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

StringTokenizer errors

Pip Vo

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.util.StringTokenizer;
public class tokenizer2
public static void get_data1()
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())
} // end try
catch(IOException e) {System.out.println("ERROR!");}
} // end get_data1()

public static void main(String s[])
Jim Yingst

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

Joined: Jul 18, 2001
Posts: 12
Thanks for the reply. My error messages: cannot resolve symbol
symbol : constructor StringTokenizer (
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)
subject: StringTokenizer errors
It's not a secret anymore!