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

后端 未结 15 1762
挽巷
挽巷 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:40

    You can do that with Apache FileUtils library. No memory problem. I did check with visualvm.

      Iterator it = FileUtils.iterateFiles(folder, null, true);
      while (it.hasNext())
      {
         File fileEntry = (File) it.next();
      }
    

    Hope that helps. bye

提交回复
热议问题