import java.io.*;

class  Tokenizer  
   {
   public static void main( String args[] ) throws Exception 
      {
      String sample = "myfile.txt";
      InputStreamReader in;
      FileInputStream file = new FileInputStream(sample);
      in = new InputStreamReader( file);
      StreamTokenizer parser = new StreamTokenizer( in );
      
      while ( parser.nextToken() != StreamTokenizer.TT_EOF )
         {
         if ( parser.ttype == StreamTokenizer.TT_WORD)
            System.out.println( "A word: " + parser.sval );
         else if  ( parser.ttype == StreamTokenizer.TT_NUMBER )
            System.out.println( "A number: " + parser.nval );
         else if  ( parser.ttype == StreamTokenizer.TT_EOL )
            System.out.println( "EOL" );
         else
            System.out.println( "Other: " + (char) parser.ttype );
         }   
      }
   }

the EOL is not reconize??? Althought i have a \n in my text file it doesnt seem to know its already an EOL.

Question no 2

import java.util.*;
public class State{
	String id;
	boolean Start,Final;

	List trans= new ArrayList();


	int counter;
	//constructer
	public State(String name){
		id=name;
		Start=false;
		Final=false;
	
	
		
	}
	//set the state as a start state
	public void setAsStart(){
		Start=true;
	}
	//set the state as a final state
	public void setAsFinal(){
		Final=true;
	}
	//returns true if the state is a start state
	public boolean isStart(){
		return Start;
	}
	//returns true if state is a final state
	public boolean isFinal(){
		return Final;
	}
	//add a transition to a state
	//this method adds a transition until the array is full. if the array is already full the catch will catch it
	public void addTransition(Transition t){
		trans.add(t);
	}
	public int getNumOfTransitions(){
		return trans.size();
	}
		
}

--------------------Configuration: <Default>--------------------
Note: \\Server3\users\0321468\State.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Process completed.
i got this error. what did i do wrong???

Recommended Answers

All 3 Replies

StreamTokenizer(InputStream is)
Deprecated. As of JDK version 1.1, the preferred way to tokenize an input stream is to convert it into a character stream, for example:
Reader r = new BufferedReader(new InputStreamReader(is));
StreamTokenizer st = new StreamTokenizer(r);

Why are you using a deprecated constructor?
You should ALWAYS avoid ANY deprecated method or class.

TT_EOL indicates that the end of line has been read. The field can only have this value if the eolIsSignificant method has been called with the argument true.

Did you even read the Javadoc?
It says quite clearly that you MUST take a very specific action to ever get that flag returned at all, an action you didn't take.

i got this error. what did i do wrong???

That's not an error, it's a warning.
You're compiling against a 1.5 compiler using code that uses collections without properly typing them.
Read up on generics.

sorry for the late reply. got busy.

anyway i just started learning a few IO stuff on java. The first code was actually taken from the internet. I was searching for lessons bout tokenizers.
so it means the site was teaching wrong stuff.

That's not an error, it's a warning.
You're compiling against a 1.5 compiler using code that uses collections without properly typing them.
Read up on generics.


ok i think il do a further study on that.

thanks anyway

not necessarilly wrong so much as heavily outdated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.