public static void porterMain(String[] stemFile) throws IOException
{
   char[] w = new char[501];
   Stemmer s = new Stemmer(); 
   for (int i = 0; i < stemFile.length; i++)
   try
   {
      FileInputStream in = new FileInputStream(stemFile[i]);
      FileWriter targetFileWriter = new FileWriter(stemFile[i] + "stemed");

      try
      { while(true)

        {  int ch = in.read();
           if (Character.isLetter((char) ch))
           {
              int j = 0;
              while(true)
              {  ch = Character.toLowerCase((char) ch);
                 w[j] = (char) ch;
                 if (j < 500) j++;
                 ch = in.read();
                 if (!Character.isLetter((char) ch))
                 {
                    /* to test add(char ch) */
                    for (int c = 0; c < j; c++) s.add(w[c]);

                    /* or, to test add(char[] w, int j) */
                    /* s.add(w, j); */

                    s.stem();
                    {  String u;

                       /* and now, to test toString() : */
                      u = s.toString();
                       
                       /* to test getResultBuffer(), getResultLength() : */
                       /* u = new String(s.getResultBuffer(), 0, s.getResultLength()); */
                       //System.out.print(u);
                       targetFileWriter.write(u + "\n");
                    }
                    break;
                 }
              }
           }
           if (ch < 0) break;
           System.out.print((char)ch);
        }
      targetFileWriter.close();
      }   
      catch (IOException e)
      {  System.out.println("error reading " + stemFile[i]);
         break;
      }
   }
   catch (FileNotFoundException e)
   {  System.out.println("file " + stemFile[i] + " not found");
      break;
   }
}