我有2000行代码,由我们的DB生成,输出就像这样
CREATE UIX:NAME=JSS,RRTE:TTRE,EMAC:TRUE,CHECK:TRUE,YYEE:FALSE
GL0/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL1/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL2/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
CREATE UIX:NAME=JSS,RRTE:TTRE,EMAC:TRUE,CHECK:FALSE,YYEE:FALSE
GL0/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL0/GL1,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
CREATE UIX:NAME=JSS,RRTE:TTRE,EMAC:TRUE,CHECK:FALSE,YYEE:FALSE
GL0/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL1/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL2/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL3/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
CREATE UIX:NAME=JSS,RRTE:TTRE,EMAC:TRUE,CHECK:TRUE,YYEE:FALSE
GL0/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL1/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL2/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL3/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
GL4/GL0,RRTE:TTRE,EMAC:TRUE,UWQ:FALSE,ULT:TRUE
我想如果“CHECK”是假的,它会为我计算GL,我也会写方法来读取文件:
public void execToken(File f) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(f));
String line;
while ((line = br.readLine()) != null) {
StringTokenizer strt = new StringTokenizer(line, ";");
while (strt.hasMoreTokens()) {
String token = strt.nextToken();
itemConfig(token, "CREATE UIX:NAME=JSS", poolVector);
}
}
}
这是我的itemConfig mehod:
public void itemConfig(String token, String condition, Vector<String> vHead) {
if (token.startsWith(condition)) {
value = getTokenValue(token);
String[] content = value.split("[,=]");
Collections.addAll(vHead, content);
}
}
任何想法?
非常感谢...
答案 0 :(得分:0)
public void execToken(File f) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(f));
String line;
while ((line = br.readLine()) != null) {
if(line.indexOf("CHECK:FALSE") > -1) {
//Do something
} else if(line.indexOf("CHECK:TRUE") > -1) {
int i = 0;
while(!(line = br.readLine).startsWith("CREATE")) {
i++;
}
// You have amount of GL's
}
StringTokenizer strt = new StringTokenizer(line, ";");
while (strt.hasMoreTokens()) {
String token = strt.nextToken();
itemConfig(token, "CREATE UIX:NAME=JSS", poolVector);
}
}
}