主函数如下,想把路径那里改成整个文件夹用正则表达式搜索文件应该怎么改?
public static void main(String[] args)throws Exception {
int matchTime=0;//匹配次数
List> strs = new ArrayList>();//字符串
try
{
File file=new File("E:\mcssmq.2018082016.audit.001.log");//路径
if (file.isFile()&&file.exists()) {//是否存在
InputStreamReader read=new InputStreamReader(new FileInputStream(file));
BufferedReader bufferedReader=new BufferedReader(read);
String lineTxt = null;//读取一行
while ((lineTxt = bufferedReader.readLine()) != null)
{
matchTime=getMatchTime(matchTime,strs,lineTxt);
matchTime = 0;
}
read.close();
//System.out.println(strs);
/*for(int i=0;i<lists1.size();i++)
{ for(int j=0;j<lists2.size();j++)
{ if (i==j){ lists3.add(lists2.get(j)+lists1.get(i)) ; } } } */
//int i = 0;
List<String> line;
String str;
for(int i=0;i<strs.size();i++){
line = strs.get(i);
for(int j=0;j<line.size();j++){
str = line.get(j);
System.out.println(str);//遍历
}
}
}else {
System.out.println("找不到指定文件");
}
}
catch (Exception e) {
System.out.println("读取文件内容出错");// TODO: handle exception
e.printStackTrace();
}
}
import os
path='/tmp'
for dirpath,dirnames,filenames in os.walk(path):
for file in filenames:
fullpath=os.path.join(dirpath,file)
print fullpath
文件名再用正则进行匹配符合的文件名噻