List files recursively in Kotlin

前端 未结 1 1351
醉梦人生
醉梦人生 2021-02-02 06:20

to list files in a directory with kotlin, i used list() and listFiles() functions:

File(\"/tmp\").list().forEach { println(it) }
File(\"/tmp\").listFiles().forEa         


        
1条回答
  •  醉话见心
    2021-02-02 06:48

    Use one of .walk(...), .walkBottomUp() or .walkTopDown() extensions for File, which differ only in the order in which the files appear and all produce a FileTreeWalk, that implements Sequence:

    File("/tmp").walkTopDown().forEach { println(it) }
    

    0 讨论(0)
提交回复
热议问题