zoukankan      html  css  js  c++  java
  • 一个关于遍历文件夹下的文件内容,遍历Map的key和value的例子


    public class FindErrors {

    public static void main(String[] args) {
    System.out.println("Jobs Started!");

    // Searching loop log directory
    String filename = "c:\wolfeTest\log\";
    File logDir = new File(filename);
    File logList[] = logDir.listFiles();

    Map<String, String> errorsMSG = new HashMap<String, String>();
    // Loop and read each file
    String line = "";
    String str_errors = "";
    int site = -1;
    for (int i = 0; i < logList.length; i++) {

    try {
    BufferedReader br = new BufferedReader(new FileReader(filename + logList[i].getName().toString()));

    while ((line = br.readLine()) != null) {
    site = line.indexOf("Rows not loaded due to data errors");
    if (site != -1) {
    str_errors = line.substring(0, site).trim();
    // If there any error, put in the map
    if(!str_errors.equals("0"))
    errorsMSG.put(logList[i].getName().toString(), str_errors);
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    // Loop the map(errorsMSG)
    Set set = errorsMSG.keySet();
    for (Iterator iter = set.iterator(); iter.hasNext();) {
    String key = (String) iter.next();
    String value = (String) errorsMSG.get(key);
    System.out.println("fileName: " + key + ", Errors: " + value);
    }

    System.out.println("Jobs Finished!");
    }
    }

  • 相关阅读:
    谈自由 , ASP.NET Core才是未来?
    asp.net core 实现 api网关 进行 api版本控制
    Oracle查询语句参考
    Go语言
    软件测试
    软件设计的重构、重写、重载
    Office 365-sharepoint online
    Pandas入门
    调用Baidu云、人脸识别接口
    Oracle 11g 安装小记
  • 原文地址:https://www.cnblogs.com/wolfe/p/3161395.html
Copyright © 2011-2022 走看看