How to list a 2 million files directory in java without having an “out of memory” exception

后端 未结 15 1798
挽巷
挽巷 2020-12-06 00:04

I have to deal with a directory of about 2 million xml\'s to be processed.

I\'ve already solved the processing distributing the work between machines and threads us

15条回答
  •  爱一瞬间的悲伤
    2020-12-06 00:38

    Try this, it works to me, but I hadn't so many documents...

    File dir = new File("directory");
    String[] children = dir.list();
    if (children == null) {
       //Either dir does not exist or is not a  directory
      System.out.print("Directory doesn't  exist\n");
    }
    else {
      for (int i=0; i

提交回复
热议问题