john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

parsetesttokenizer.java

import java.io.*;
import java.util.StringTokenizer;

class parsetest
{
    public static void main(String[] args) throws Exception
    {
        String temp;

        String prelink,
               postlink,
               hyperlink;

        int templength=0,
            prelinkstart=0,
            prelinkend=0,
            linkstart=0,
            linkend=0,
            postlinkstart=0,
            postlinkend=0;

        String outfilename = "temp.txt";
        PrintWriter fout = null;

        BufferedReader fin = null;
        StringTokenizer st = null;

        fin = new BufferedReader(new FileReader("www.cnn2.com.html"));
        fout = new PrintWriter(new BufferedWriter(new FileWriter(outfilename)));


        temp = fin.readLine();
        templength = temp.length();
        System.out.println("length of input: " + templength);

        st = new StringTokenizer(temp, "</a>");
        templength = st.countTokens();
        System.out.println("number of tokens: " + templength);

        while(st.hasMoreTokens())
        {
            String key = st.nextToken();
            fout.println(key + "\n");
        }



/*      prelinkstart = 0;
        prelinkend = temp.indexOf("<a href") - 1;
System.out.println(prelinkend);
        prelink = temp.substring(prelinkstart, prelinkend);
        postlink = temp.indexOf(prelinkend, templength);

        linkstart = prelinkend + 1;
        linkend = postlink.indexOf('>');
        hyperlink = postlink.substring(linkstart, linkend);
        System.out.println(hyperlink);


/*
        while( temp !=  null)
        {
//          if(
//          fout.println(

            System.out.println(temp);
            temp = fin.readLine();
        }
*/
        fin.close();
        fout.close();

    }//end of main
}//end of class

  • « bitLogic.java
  • parsetest.java »

Published

Sep 24, 2001

Category

java

~110 words

Tags

  • java 252
  • parsetesttokenizer.java 1