方法:
public static Stream<Path> walk(Path start,
FileVisitOption... options)
throws IOException
public static Stream<Path> walk(Path start,
int maxDepth,
FileVisitOption... options)
throws IOException
通过遍历以Path
给定起始文件为根的文件树,返回 延迟填充的Stream
。
参数:
start
- 起始文件
maxDepth
- 要访问的最大目录级别数
options
- 配置遍历的选项
返回:
java.util.stream.Stream,
java.nio.file.Path
的Stream
例子
import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class WalkExample {
public static void main(String... args) throws IOException {
Path start = Paths.get("d:\\usr");
Stream<Path> stream = Files.walk(start, 3, FileVisitOption.FOLLOW_LINKS);
stream.limit(9999).forEach(System.out::println);
}
}
输出
d:\usr
d:\usr\bin
d:\usr\bin\encode_keychange.exe
d:\usr\bin\mib2c
d:\usr\bin\mib2c.bat
d:\usr\bin\Microsoft.VC90.CRT.manifest
d:\usr\bin\msvcm90.dll
d:\usr\bin\msvcp90.dll
d:\usr\bin\msvcr90.dll
d:\usr\bin\net-snmp-perl-test.pl
d:\usr\bin\netsnmp.dll
d:\usr\bin\snmpbulkget.exe
d:\usr\bin\snmpbulkwalk.exe
d:\usr\bin\snmpconf
d:\usr\bin\snmpconf.bat
d:\usr\bin\snmpd.exe
d:\usr\bin\snmpdelta.exe
d:\usr\bin\snmpdf.exe
d:\usr\bin\snmpget.exe
d:\usr\bin\snmpgetnext.exe
d:\usr\bin\snmpnetstat.exe
d:\usr\bin\snmpset.exe
d:\usr\bin\snmpstatus.exe
d:\usr\bin\snmptable.exe
d:\usr\bin\snmptest.exe
d:\usr\bin\snmptranslate.exe
d:\usr\bin\snmptrap.exe
d:\usr\bin\snmptrapd.exe
d:\usr\bin\snmpusm.exe
d:\usr\bin\snmpvacm.exe
d:\usr\bin\snmpwalk.exe
d:\usr\bin\traptoemail
d:\usr\bin\traptoemail.bat
d:\usr\docs
d:\usr\docs\COPYING
d:\usr\docs\Net-SNMP.chm
d:\usr\etc
d:\usr\etc\snmp
d:\usr\etc\snmp\snmp.conf
d:\usr\include
d:\usr\include\net-snmp
d:\usr\include\net-snmp\agent
d:\usr\include\net-snmp\net-snmp-config.h
d:\usr\log
d:\usr\perl
d:\usr\perl\NetSNMP.ppd
d:\usr\perl\x86
d:\usr\perl\x86\NetSNMP.tar.gz
d:\usr\README.txt
d:\usr\registeragent.bat
d:\usr\registertrapd.bat
d:\usr\share
d:\usr\share\snmp
d:\usr\share\snmp\mib2c-data
d:\usr\share\snmp\mib2c.access_functions.conf
d:\usr\share\snmp\mib2c.array-user.conf
d:\usr\share\snmp\mib2c.check_values.conf
d:\usr\share\snmp\mib2c.check_values_local.conf
d:\usr\share\snmp\mib2c.column_defines.conf
d:\usr\share\snmp\mib2c.column_enums.conf
d:\usr\share\snmp\mib2c.column_storage.conf
d:\usr\share\snmp\mib2c.container.conf
d:\usr\share\snmp\mib2c.create-dataset.conf
d:\usr\share\snmp\mib2c.emulation.conf
d:\usr\share\snmp\mib2c.genhtml.conf
d:\usr\share\snmp\mib2c.int_watch.conf
d:\usr\share\snmp\mib2c.iterate.conf
d:\usr\share\snmp\mib2c.iterate_access.conf
d:\usr\share\snmp\mib2c.mfd.conf
d:\usr\share\snmp\mib2c.notify.conf
d:\usr\share\snmp\mib2c.old-api.conf
d:\usr\share\snmp\mib2c.perl.conf
d:\usr\share\snmp\mib2c.raw-table.conf
d:\usr\share\snmp\mib2c.row.conf
d:\usr\share\snmp\mib2c.scalar.conf
d:\usr\share\snmp\mib2c.table_data.conf
d:\usr\share\snmp\mibs
d:\usr\share\snmp\snmpconf-data
d:\usr\snmp
d:\usr\snmp\persist
d:\usr\snmp\persist\mib_indexes
d:\usr\temp
d:\usr\uninst.exe
d:\usr\unregisteragent.bat
d:\usr\unregistertrapd.bat
d:\usr\新建文,本文档.txt
d:\usr\新建文本文档 (2).txt