i have wrote the code to read a 3rd column of a file(treeout1.txt) and write those contents in another file(tree.txt).and now i want to open tree.txt and write the contents to stem.txt,where tree.txt contents a single word in each row and a delimiter is found at the end of each line.i have attached that txt file below.you can view that to have better understanding.now i want to write the words into a line till a delimiter "###" is found...for example 'the girl own paper' and next line vol and so on....i have tried that but ArrayIndexOutOfBoundsException comes for a[]...why?and how to resolve that?
the text file tree.txt is given below
the
girl
own
paper
###
vol
###
viii
###
no
###
@card@
###
October
@card@
@card@
###
price
one
penny
###
as
the
baron
have
conjecture
the
housemaid
whom
he
have
call
out
of
the
nursery
to
look
for
###
lons
cane
on
find
her
master
have
go
without
it
do
not
hurry
back
but
stop
talk
###
Code:
 package simple;
 import java.io.*;
 import java.util.Scanner;
 import java.util.StringTokenizer;
 public class Simple {
   public static void main(String[] args) throws IOException {
     String line;
     String line2;
     String[] a = new String[100];
     int i = 0;
     try {
       BufferedReader br = new BufferedReader(new FileReader("C:/TreeTagger/treeout1.txt"));
       BufferedWriter output = new BufferedWriter(new FileWriter("D:/tree.txt"));
       String separator = System.getProperty("line.separator");
       while ((line = br.readLine()) != null) {
         StringTokenizer st2 = new StringTokenizer(line, "\n");
         while (st2.hasMoreElements()) {
           String line1 = (String) st2.nextElement();
           String[] array = line1.split("\\s+", 3);
           //System.out.println(array[2]);
           output.append(array[2]);
           output.newLine();
         }
       }
       output.close();
       br.close();
       BufferedReader br1 = new BufferedReader(new FileReader("D:/tree.txt"));
       BufferedWriter out = new BufferedWriter(new FileWriter("D:/stem.txt"));
       while ((line2 = br1.readLine()) != null) {
         StringTokenizer st = new StringTokenizer(line2, " ");
         while (st.hasMoreTokens()) {
           String element = st.nextToken();
           System.out.println(element);
           while (element != "###") {
             a[i] = element;
             i++;
           }
           out.append(a[i]);
           element = element.replace(element, "");
         }
       }
     } catch (IOException e) {
     }
   }
 }
 
    