一起学习
import java.io.*;
import java.util.*;
public class HtmlTokenizer {
public static int HTML_TEXT=-1;
public static int UNKNOWN=-2;
static int HTML_EOF=-3;
static int H=-4;
static int R=-5;
static int T=-6;
static int B=-7;
static int M=-8;
static int E=-9;
static int END=-10;
Vector Hv=new Vector();
Vector Rv=new Vector();
Vector Tv=new Vector();
Vector Bv=new Vector();
Vector Mv=new Vector();
Vector Ev=new Vector();
public StreamTokenizer HtmlStream;
boolean outsideTag=true;
public void HtmlTokenizer(String month)
{
BufferedReader reader=null;
int tagType;
int oldtagType=0;
String filename="/" month;
try{
reader=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
}catch(FileNotFoundException e){
System.out.println(e.getMessage());
}
HtmlStream=new StreamTokenizer(reader);
HtmlStream.resetSyntax();
HtmlStream.wordChars(0,255);
HtmlStream.ordinaryChar('<');
HtmlStream.ordinaryChar('>');
}
public int nextHtml()
{
int token;
try{
switch(token=HtmlStream.nextToken())
{
case StreamTokenizer.TT_EOF: return HTML_EOF;
case '<': outsideTag=false; return nextHtml();
case '>': outsideTag=true; return nextHtml();
case StreamTokenizer.TT_WORD:
if(HtmlStream.sval.toUpperCase().equals("R")&& !outsideTag ) {return R;}
else if(HtmlStream.sval.toUpperCase().equals("H") && !outsideTag ) {return H;}
else if(HtmlStream.sval.toUpperCase().equals("B") && !outsideTag ) {return B;}
else if(HtmlStream.sval.toUpperCase().equals("T") && !outsideTag ) {return T;}
else if(HtmlStream.sval.toUpperCase().equals("M") && !outsideTag ) {return M;}
else if(HtmlStream.sval.toUpperCase().equals("E") && !outsideTag ) {return E;}
else if(HtmlStream.sval.toUpperCase().equals("/R") && !outsideTag ) {return END;}
default:return UNKNOWN;
}
}catch(IOException e){
System.out.println("Error:" e.getMessage());
}
return UNKNOWN;
}
public void get(String card_no)
{
String Rtmp=null;
String Htmp=null;
String Ttmp=null;
String Btmp=null;
String Mtmp=null;
String Etmp=null;
String UNKNOWNtmp=null;
int tagType;
int oldtagType=0;
while((tagType=nextHtml())!=HTML_EOF){
if(tagType==UNKNOWN&&oldtagType==H){
Htmp=HtmlStream.sval;
Hv.addElement(Htmp);
}else if(tagType==UNKNOWN&&oldtagType==T){
Ttmp=HtmlStream.sval;
Tv.addElement(Ttmp);
}else if(tagType==UNKNOWN&&oldtagType==B){
Btmp=HtmlStream.sval;
Bv.addElement(Btmp);
}else if(tagType==UNKNOWN&&oldtagType==M){
Mtmp=HtmlStream.sval;
Mv.addElement(Mtmp);
}
if(tagType==END)
{
if(Ttmp.indexOf(card_no)!=-1)
{
break;
}
Hv.removeAllElements();
Tv.removeAllElements();
Bv.removeAllElements();
Mv.removeAllElements();
}
oldtagType=tagType;
}
}
public boolean isnone()
{
return Hv.isEmpty();
}
public String getH()
{
return Hv.elementAt(0).toString();
}
public String getT()
{
return Tv.elementAt(0).toString();
}
public String getB()
{
return Bv.elementAt(0).toString();
}
public String getM(int i)
{
return Mv.elementAt(i).toString();
}
public int Msize()
{
return Mv.size();
}
}
/*
文件格式
213002|xxxxxxxxxxx|xxxxx|xxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx |xxxx-xx-xx
xxxx| xxxx.xx
xxxx-xx-xx|xxxxxxx| |xxx.xx|xxxx.xx|xxxx.xx
xxxx-xx-xx|xxxxxxx| |xxx.xx|xxxx.xx|xxxx.xx
xxxx-xx-xx|xxxxxxx| |xxx.xx|xxxx.xx|xxxx.xx
xxxx-xx-xx|xxxxxxx| |xxx.xx|xxxx.xx|xxxx.xx
*/
下载本文示例代码
StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用StreamTokenizer类的使用
阅读(254) | 评论(0) | 转发(0) |