how can i use a
string tokenizer in a loop.I need to read each line of a file and split it on a delimiter.
My txt file is in the format
A|B|C|D
i have used the following:
try
{
FileReader fr=new FileReader("myfile.txt");
BufferedReader br=new BufferedReader(fr);
while((line=br.readLine())!=null)
{
StringTokenizer st=new StringTokenizer(line,"|");
while (st.hasMoreTokens())
{
a=st.nextToken();
b=st.nextToken();
c=st.nextToken();
d=st.nextToken();
e=st.nextToken();
}
}
}catch(Exception ex){}
What happens is it reads one line then gives nosuchelementfound exception .can u suggest a way of gettin through this.Maybe i need to undefine st object at the end of the loop.If it is tht how do i undefine the object.