This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringTokenizer errors

 
Pip Vo
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pip Vo
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic