日期:2014-05-20 浏览次数:20920 次
import java.io.*;
import java.util.regex.*;
public class updataPage {
public static void main(String[] args) {
try{
File dir=new File("C:/jsptest/test/WebRoot/08");
String file[]=dir.list();
//for(int i=0;i<file.length;i++){
int i=1;
File f=new File("C:/jsptest/test/WebRoot/08/"+file[i]);
//if(f.isDirectory())continue;
FileInputStream fis=new FileInputStream(f);
//BufferedInputStream bis=new BufferedInputStream(fis);
String str2="";
byte[] b=new byte[1024];
int j=0;
while((fis.read(b))!=-1){
j++;
String s=new String(b,"UTF-8");
str2=str2+s;
b=new byte[1024];
}
System.out.println(file[i]+" "+j);
fis.close();
Pattern regex=Pattern.compile("request\\.getParameter\\(\"[a-zA-Z]+\"\\)");
Matcher m=regex.matcher(str2);
System.out.println("regex:"+regex.toString());
String[] strarr=new String[20];
int t=0;
while(m.find()){
strarr[t]=m.group();
t++;
}
t=0;
while(strarr[t]!=null){
String tempstr=strarr[t];
System.out.println(tempstr);
/*下面这行如果不注释的话系统会报t++;这一行错误,错误信息:
java.util.regex.PatternSyntaxException: Unclosed group near index 35
request\.getParameter\("("submit"\)^*/
//regex=Pattern.compile("request\\.getParameter\\(\""+tempstr.substring(20,tempstr.length()-2)+"\"\\)");
System.out.println(regex);
t++;
}
//String rall=m.replaceAll("class=\"fontstyle\"");
//System.out.println(rall);
//FileOutputStream fos=new FileOutputStream(new File("C:/test/"+file[i]));
//fos.write(rall.getBytes("UTF-8"));
//fos.close();
//System.out.println(file[i]);
//}
}catch(Exception e){
e.printStackTrace();
}
}
}