Hi, i have encounter a problem when trying to use a Reader object. i cannot detect the end of file thus the whole
word cannot be printed out. Hope someone will enlighten me.
import java.io.*;
public class Tokenizer
{
private Reader reader;
public Tokenizer(Reader r)
{
reader = r;
}
public
String nextWord()
{
String word = "";
int next = 0;
char c = 'a';
try
{
while (next != -1)//while "next" not end of input
{
next = reader.read();
if (next != -1) //if not end of input
c = (char) next; //cast "next" into character and store in "c"
word = word + c; //add character to word
}
}
catch (IOException ex)
{
System.out.println("IOException occurs");
}
return word;
}
}