How to retrieve a list of directories QUICKLY in Java?

后端 未结 14 957
轮回少年
轮回少年 2020-12-01 12:45

Suppose a very simple program that lists out all the subdirectories of a given directory. Sound simple enough? Except the only way to list all subdirectories in Java is to u

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 12:52

    if your OS is 'stable' give a try to JNA:

    • opendir/readdir on UNIX
    • FindFirstFile and related API on Windows
    • Java7 with NIO2

    these are all "streaming API". They doesn't force you to allocate a 150k list/array before start searching. IMHO this is a great advantage in your scenario.

提交回复
热议问题