java 遍历文件夹中的所有文件

来源:互联网 发布:过期域名删除查询 编辑:程序博客网 时间:2024/06/04 17:59

本文是不包括文件夹下还有文件夹的情况,代码如下:

public static void statisCallingIP(){ Set<String> IPSet = null;IPSet = new HashSet<String>(); FileReader fr = null;String line = null;BufferedReader br = null;try {File dir = new File("d:/Users/jaloli/Desktop/");File[] files = dir.listFiles();  //获取文件夹中的所有文件for(File file : files){  //遍历文件夹中的所有文件Set<String> IPSetTemp = new HashSet<String>();fr = new FileReader(file);br = new BufferedReader(fr);String[] temp1 = null;String[] temp2 = null;while((line = br.readLine())!=null ){if(line.contains("/activi/search")){temp1 = line.split("200 OK");temp2 = temp1[0].split(".*:\\d{1,5}");//贪婪匹配冒号数字空格IPSetTemp.add(temp2[temp2.length-1].trim());}}IPSet.addAll(IPSetTemp); //添加到整体的set 中}br.close();} catch (Exception e) {e.printStackTrace();}for(String ip : IPSet){System.out.println(ip);}IPSet.clear();}


0 0
原创粉丝点击