62,632
社区成员




public class ExtractOperation {
static String filePath = "./source/";
public void extraction(String filePath) throws IOException{
GetFileInfo gfn = new GetFileInfo();
filePath=filePath+gfn.getFileName(filePath)+"/";
long num = gfn.getFileNum(filePath); for(int i=1;i<=num;i++){
char c[] = new char[3000]; //创建可容纳3000个字符的数组
FileReader fr = new FileReader(filePath+String.valueOf(i)+"/"+"index"+String.valueOf(i)+".txt");
int number = fr.read(c); //将数据读入字符数组c内,并返回读取的字符数
String str=new String(c,0,number); //将字符串数组转换成字符串
Extraction extra = new Extraction();
try{
extra.getAttri(str);
}
catch(IOException e){
e.printStackTrace();
}
}
}
public static void main(String args[])
{
ExtractOperation eo = new ExtractOperation();
try {
eo.extraction(filePath); } catch (IOException e) {
e.printStackTrace();
}
}
}
public class GetFileInfo{
public String getFileName(String filePath)
{
String fileName=null;
int lastNum=0;
File file=new File(filePath);
String[] test=file.list();
lastNum=file.list().length;
fileName=test[lastNum-1];
return fileName;
}
public long getFileNum(String filePath)
{
long lastNum;
File file=new File(filePath);
lastNum=file.list().length; return lastNum;
}
}
public class Extraction{
public void getAttri(String str)throws IOException
{
File file = new File("./source/Parameter.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
String s1="(?<=<td class=(\\u0022)tdTitle(\\u0022)>)\\w+(?=</td>)";//匹配参数名称
Pattern p1=Pattern.compile(s1);
Matcher m1=p1.matcher(str);
while(m1.find())
{
String s=m1.group();
bw.write(s);
}
bw.close();
}
}
File file = new File("./source/Parameter.txt");