in this program, I am trying to read from a file each couple of words ends with this char "|" as a token and then write the out put in another file.
my code is working fine just for 1 line, but the rest is not
i don't know why?. is it from the loop or what?
===========================================================
import java.util.*;
import java.io.*;
import java.*;
public class
Test {
public static void main(
String[] args) throws IOException
{
//FileReader fr=new FileReader("test1.txt");
//FileWriter fw=new FileWriter("testTest.txt");
BufferedReader buffer=new BufferedReader(new FileReader("test1.txt"));
PrintWriter pw = new PrintWriter(new FileWriter("TestFileOut.txt"));
String str=buffer.readLine();
try
{
for (int i=0;i<7;i++)
{
str=buffer.readLine();
StringTokenizer st = new StringTokenizer(str, "|");
while (st.hasMoreTokens())
{
//System.out.println(st.nextToken());
pw.println(st.nextToken());
}
pw.close();
}
}
catch(Exception e)
{
System.out.println(" ");
}
}
}
==============================================================
*****************
TXT FILE
test1.txt
| Eric John Smith | iam 22 years old | thanks |
| Jessica Norman King | iam 19 years old | thanks |
****************
Regards