directory-content

Get large directory content faster (java.io.File alternatives)

旧街凉风 提交于 2019-11-28 09:52:43
I've used the old, obsolete java.io.File.listFiles() for too long. The performance is not so good. It is: Expensive, since it creates a new File object for each entry. Slow, because you have to wait for the array to be completed before starting the processing. Very bad, especially if you need to work only on subset of the content. What are the alternatives? The Java 7's java.nio.file package can be used to enhance performance. Iterators The DirectoryStream<T> interface can be used to iterate over a directory without preloading its content into memory. While the old API creates an array of all

Get large directory content faster (java.io.File alternatives)

若如初见. 提交于 2019-11-27 03:15:28
问题 I've used the old, obsolete java.io.File.listFiles() for too long. The performance is not so good. It is: Expensive, since it creates a new File object for each entry. Slow, because you have to wait for the array to be completed before starting the processing. Very bad, especially if you need to work only on subset of the content. What are the alternatives? 回答1: The Java 7's java.nio.file package can be used to enhance performance. Iterators The DirectoryStream<T> interface can be used to