检查不匹配的tag

检查不匹配的tag
package test.file;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class CheckMatchLabel {
 
 public static void main(String args[]){
        String path="C:/test123/";
        String[] folder={"1","2","3","4","5","6","7"};
        String writerfile="e:/writerfile.txt";
        String[] word1={"<table","<th","<td","<tr","<div","<p","<session","<logic","<font"};
        String[] word2={"</table","</th","</td","</tr","</div","</p","</session","</logic","</font"};
     
        //check writerfile.txt  if exist then delete it
        fileExist(writerfile);
       
        //check all files,then write them to writerfile.txt
        for(int i=0;i<folder.length;i++){
         String path2=path+folder[i];
               findFile(path2,writerfile);
        }
       
        readpath(writerfile,word1,word2);     
 }
 
 //check all files in this folders;
 public static void findFile(String folderpath,String writerfile){
        File file = new File(folderpath);  
        String[] fns =file.list();
       
        try{
       FileWriter fw = new FileWriter(writerfile,true);
       BufferedWriter bw = new BufferedWriter(fw);
       for(int i=0;i<fns.length;i++){
        String path2=folderpath+"/"+fns[i];
              bw.write(path2);
              bw.newLine();
          }
          bw.flush();
          bw.close();
         }catch(IOException e){
             e.printStackTrace();
            }
    }
 
 //read files form writerfile.txt,then check it
 public static void readpath(String file,String[] word1,String[] word2){
     try{
      
      FileReader fr = new FileReader(file);
      BufferedReader br = new BufferedReader(fr);
     
   String readoneline;
   int i=0;
   while ((readoneline = br.readLine()) != null) {
                 readline(readoneline,word1,word2);
   }      
           br.close();
           fr.close();
          }catch(IOException e){
              e.printStackTrace();
         }
     }
 public static void readline(String file,String[] word1,String[] word2){
     try{
      FileReader fr = new FileReader(file);
      BufferedReader br = new BufferedReader(fr);
   String readoneline;
   
   int[] num=new int[word1.length];
   for(int i=0;i<num.length;i++){
    num[i]=0;
   }
   
   while ((readoneline = br.readLine()) != null) {
    for(int i=0;i<word1.length;i++){
     if(readoneline.indexOf(word1[i])!=-1){
      num[i]++;
     }
     if(readoneline.indexOf(word2[i])!=-1){
      num[i]--;
     }
    }
     }
   
   for(int i=0;i<num.length;i++){
    if(num[i]!=0){
     System.out.println(file+":"+word1[i]+":"+num[i]);
    }
   }
         
           br.close();
           fr.close();
          }catch(IOException e){
              e.printStackTrace();
         }
     }
 
     // check writerfile.txt  if exist then delete it
 public static void fileExist(String filePath){
  if(new File(filePath).exists()){
         try {
             filePath = filePath.toString();
             java.io.File myDelFile = new java.io.File(filePath);
             myDelFile.delete();
         }
         catch (Exception e) {
             System.out.println("delete file error");
             e.printStackTrace();

         }
  }
 }

}

**********************************************************************

package serch.cs;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Serch {

 /**
  * @param args
  */
 /**
  * @param args
  */
 public static void main(String[] args) {
  String path="C:/test";
  String bet=path+"/1";
  String common=path+"/2";
  String help=path+"/3";
  String odds=path+"/4";
  String payment=path+"/5";
  String refer=path+"/6";
  String transfer=path+"/7";
  
  String serchStart="<section class=\"roundedArea\">";
  //String serchStart="<section";
  String serchEnd="</section>";
  String serchBody="<logic:equal";
        int section=0;
        int mark=0;
        int count=0;
  File mydir=new File(path);
  if(mydir.exists()&&mydir.isDirectory()){
   File[] dirContents=mydir.listFiles();
   if(dirContents!=null){
    for(int i=0;i<dirContents.length;i++){
     if(dirContents[i].isDirectory()){
      File[] files=dirContents[i].listFiles();
      if(files!=null){
       for(int j=0;j<files.length;j++){
        if(!files[j].isDirectory())
         try{
          FileReader fr=new FileReader(files[j]);
          BufferedReader buff=new BufferedReader(fr);
          boolean no=false;
          while(!no){
           String line=buff.readLine();
           if(line==null) no=true;
           else{
               if(line.indexOf(serchStart)!=-1){
                section=1;
               }
               if(section==1){
                if(line.indexOf(serchBody)!=-1)
                 mark=1;
                //count++;
               }
               if(line.indexOf(serchEnd)!=-1)
                section=0;
              }
          }
          buff.close();
         }catch(IOException e){
          System.out.println("Error--"+e.toString());
         }
         if(mark==1){
          System.out.println(files[j]);
          count++;
          mark=0;
         }
       }
      }
     }
    }
   }
  }
  System.out.println("***"+count);
       
 }

}
********************************************************************

package search.src;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Search {

 /**
  * @param args
  */
 /**
  * @param args
  */
 public static void main(String[] args) {
  String path="C:/1";
  String bet=path+"/1";
  String common=path+"/2";
  String help=path+"/3";
  String odds=path+"/4";
  String payment=path+"/5";
  String refer=path+"/6";
  String transfer=path+"/7";
  
  //String serchStart="<section class=\"roundedArea\">";
  //String searchStart="<logic:messagesPresent";
  String searchStart="<html:form";
  //String serchEnd="</section>";
        //String searchEnd="</logic:messagesPresent>";
  String searchEnd="</html:form";
  //String serchBody="<logic:equal";
        //String searchBody="<br";
  String searchBody="\"\"";
        String searchConditionStart="<section";
        String searchConditionEnd="</section";
        int section=0;
        int mark=0;
        int count=0;
        int isCondition=0;
  File mydir=new File(path);
  if(mydir.exists()&&mydir.isDirectory()){
   File[] dirContents=mydir.listFiles();
   if(dirContents!=null){
    for(int i=0;i<dirContents.length;i++){
     if(dirContents[i].isDirectory()){
      File[] files=dirContents[i].listFiles();
      if(files!=null){
       for(int j=0;j<files.length;j++){
        if(!files[j].isDirectory())
         try{
          FileReader fr=new FileReader(files[j]);
          BufferedReader buff=new BufferedReader(fr);
          boolean no=false;
          while(!no){
           String line=buff.readLine();
           if(line==null) no=true;
           else{
               if(line.indexOf(searchStart)!=-1){
                section=1;
               }
               if(section==1){
                if(line.indexOf(searchConditionStart)!=-1){
                 isCondition=1;
                }
                if(isCondition==1&&line.indexOf(searchBody)!=-1){
                 mark=1;
                }
                if(line.indexOf(searchConditionEnd)!=-1){
                 isCondition=0;
                }
               }
               if(line.indexOf(searchEnd)!=-1){
                section=0;
                   isCondition=0;
               }    
              }
          }
          buff.close();
         }catch(IOException e){
          System.out.println("Error--"+e.toString());
         }
         if(mark==1){
          System.out.println(files[j]);
          count++;
          mark=0;
         }
       }
      }
     }
    }
   }
  }
  System.out.println("***"+count);
 }

}

 ************************************************************


package spring.impl;

import java.io.*;

public class find {
 
 public static void main(String args[]){
        String path="C://";
        String[] folder={"1","2","3","4","5","6","7"};
        String writerfile="e:/writerfile.txt";
        String writerfile2="e:/writerfile2.txt";
        String word="class=\"";
        for(int i=0;i<folder.length;i++){
         String path2=path+folder[i];
               findFile(path2,writerfile);
        }
        readpath(writerfile,writerfile2,word);     
 }
 public static void findFile(String path,String writerfile){
        File file = new File(path);  
        String[] fns =file.list();
       
        try{
       FileWriter fw = new FileWriter(writerfile,true);
       BufferedWriter bw = new BufferedWriter(fw);
       for(int i=0;i<fns.length;i++){
        String path2=path+"/"+fns[i];
              bw.write(path2);
              bw.newLine();
          }
          bw.flush();
          bw.close();
         }catch(IOException e){
             e.printStackTrace();
            }
    }
 public static void readpath(String file,String writerfile,String word){
     try{
      
      FileReader fr = new FileReader(file);
      BufferedReader br = new BufferedReader(fr);
     
   String readoneline;
   int i=0;
   while ((readoneline = br.readLine()) != null) {
                 readline(readoneline,writerfile,word);
   }      
           br.close();
           fr.close();
          }catch(IOException e){
              e.printStackTrace();
         }
     }
 public static void readline(String file,String writerfile,String word){
     try{
      FileReader fr = new FileReader(file);
      BufferedReader br = new BufferedReader(fr);
      FileWriter fw = new FileWriter(writerfile,true);
      BufferedWriter bw = new BufferedWriter(fw);
   String readoneline;
   String str="";
   while ((readoneline = br.readLine()) != null) {
    str=match(readoneline,word,file);
                if(!"".equals(str)){
                 bw.write(str);
                 bw.newLine();
                }
     }       
           bw.flush();
           bw.close();
           br.close();
           fw.close();
           fr.close();
          }catch(IOException e){
              e.printStackTrace();
         }
     }

 public static String match(String line,String word,String filename){
  
  line=line.replaceAll("\\s","");
  String writerfile="e:/writerfile3.txt";
  String str="";
  String[] str2={};
  int num=line.indexOf(word);
  int num2=num+word.length();
  if(num!=-1)
  {
   str=line.substring(num2);
   str2=str.split("\"");
   str=str2[0];
  }
  if(!"".equals(str))
      matchCss(str,writerfile,filename);
  return str;
 }
 public static void matchCss(String css,String writerfile,String filename){
       String path="C:/";
       String[] file={"1.css","2.css","3.css","4.css","5.css","6.css","7.css","8.css","9.css"};
       boolean b=false;
       for(int i=0;i<file.length;i++){
        String path2=path+file[i];
     try{
       FileReader fr = new FileReader(path2);
       BufferedReader br = new BufferedReader(fr);
    String readoneline;
    while ((readoneline = br.readLine()) != null){
                 if(readoneline.indexOf(css)!=-1){
                     b=true;
         }
    }
        br.close();
        fr.close();
          }catch(IOException e){
              e.printStackTrace();
         } 
       }
      
     try{
        FileWriter fw = new FileWriter(writerfile,true);
           BufferedWriter bw = new BufferedWriter(fw);
           if(!b){
            System.out.println(css);
            bw.write(filename);
            bw.newLine();
      bw.write(css);
      bw.newLine();
             }
     bw.flush();
     bw.close();
     fw.close();
          }catch(IOException e){
              e.printStackTrace();
             }

 }
}

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值